I was wondering is there anyway to change the namespace prefix for the WCF SOAP request?
As you can see in the example below, The Envelope has namespace "http://www.w3.org/2005/08/addressing" with prefix 'a'. I want to change this to 'foo'. How can I do that. Note I dont have control over service code I can only create proxy class from the WSDL .
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.starstandards.org/webservices/2005/10/transport/operations/MyAction</a:Action>
<h:payloadManifest xmlns="http://www.starstandards.org/webservices/2005/10/transport" xmlns:xsi="http://开发者_开发技巧www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:h="http://www.starstandards.org/webservices/2005/10/transport">
<manifest contentID="Content0" namespaceURI="http://www.starstandard.org/STAR/5" element="TESTMETHOD" version="5.2.4"></manifest>
</h:payloadManifest>
<h:Identity xmlns="urn:xxx/xxx/" xmlns:h="urn:xxx/xxx">
<SiteCode>XXXXXX</SiteCode>
</h:Identity>
<a:To>urn:xxx/xxx/Method1</a:To>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">XXXXX</MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
</s:Header>
This can be done on Client or Server side by using a MessageFormatter. You can also change this with a MessageEncoder, but this has many problems.
This article describes how to do this on server side using a MessageFormatter and also the downside of a MessageEncoder:
http://vanacosmin.ro/Articles/Read/WCFEnvelopeNamespacePrefix
What you need to do is to apply the MessageFormatter client side (maybe using ApplyClientBehavior instead of ApplyDispatchBehavior). Also, in the custom message class you need to add your namespace as attribute, with the "foo" prefix (in the OnWriteStartEnvelope method).
Unfortunately, there is no easy way (like applying some attributes) that will make the change you need.
WCF provides ability to control most of the SOAP Envelop details using message contracts. But I doubt if you can do something with the namespace prefix. You can control the namespace however.
Please refer to Using Message Contracts
I'm not aware of any way to control the prefixes WCF uses in its standard message encoders.
I think you would have to write a custom message encoder if you want the message on the wire to use different prefixes.
精彩评论