Shadrack Orina
Shadrack Orina

Reputation: 7953

C# - Make WCF Accept any Soap message prefixes

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.

Upvotes: 11

Views: 1611

Answers (3)

gdenuf
gdenuf

Reputation: 890

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.

Upvotes: 2

Alex Lyman
Alex Lyman

Reputation: 15975

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.

Upvotes: 2

Shubham Sharma
Shubham Sharma

Reputation: 91

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">

Upvotes: 4

Related Questions