Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Make WCF Accept any Soap message prefixes

Tags:

c#

soap

wcf

This is the situation, there is an existing client, I need to build a server the client will be consuming. I don't own the client and am in no position to change it. The client soap message can be follows

enter image description here

How do I make my service accept both of the circled prefixes. Currently it only accepts "c2b" prefix and its not processing any requests with "ns1" prefix.

like image 884
Shadrack B. Orina Avatar asked Dec 15 '16 09:12

Shadrack B. Orina


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

Why is C named so?

Because a and b and c , so it's name is C. C came out of Ken Thompson's Unix project at AT&T. He originally wrote Unix in assembly language. He wrote a language in assembly called B that ran on Unix, and was a subset of an existing language called BCPL.


3 Answers

You are passing the DTO(Class object) to service but your wcf service is not able to recognize the exact class. So to make WCF accept any prefixes just add that prefix with proper object location. You Need to just add one more xmlns attribute to <soapenv:Envelope>.

Eg.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://cps.huawei.com/cpsinterface/c2bpayment" xmlns:c2B="http://cps.huawei.com/cpsinterface/c2bpayment">
like image 193
Shubham Sharma Avatar answered Oct 22 '22 02:10

Shubham Sharma


Honestly, you might be up a creek here. You have a client that is providing a completely invalid SOAP message -- it is using a namespace prefix that it isn't declaring at all.

I don't have time to try it out, but my first thought was maybe using XmlNamespaceDeclarationsAttribute might work -- you could provide it on your root C2BPaymentConfirmationRequest class, and pre-fill it in your constructor with "ns1" pointing at "http://cps.huawei.com/cpsinterface/c2bpayment". Worth a try. Let us know if it works out.

like image 32
Alex Lyman Avatar answered Oct 22 '22 04:10

Alex Lyman


Shubham Sharma's answer is 100% correct.

To add a little bit more explanation, these prefixes are just alias of the namespaces you declared. They don't mean anything. If you want to use ns1 as the prefix, all you need to do is to replace xmlns:c2b with xmlns:ns1 at the top.

In your case, the client doesn't know how to generate the request. Maybe it is better to advise them to use some request generation tool based on the wsdl - such as SoapUI.

like image 31
NY-M Avatar answered Oct 22 '22 03:10

NY-M