4

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>
activebiz
  • 6,000
  • 9
  • 41
  • 64
  • Why do you think you want to change the prefix? It shouldn't make any difference to anything which understands XML correctly. – Chris Dickson Jun 28 '11 at 12:57
  • I know just changing prefix should not make any difference however the service that I am going to consume , I have no control over it and dont know how its handling the SOAP request. Currently I am getting server error message related to an element which is fine expect the prefix. Its process of elimination. thx – activebiz Jun 28 '11 at 13:17
  • Thanks for all the replies. One way I think this can be achived is by using IClientMessageInspector, IEndpointBehavior as its shown http://social.technet.microsoft.com/wiki/contents/articles/how-to-inspect-wcf-message-headers-using-iclientmessageinspector.aspx. One of the event gets fired just before the request is send. At that point you can get the Row SOAP message and manipulate (prob. not advisable). Hope this helps to others. – activebiz Jun 29 '11 at 07:20
  • I'm sceptical about this. In a client message inspector you don't get access to the raw SOAP message, you get a Message object (in which the message headers are represented as a collection of Header objects) *before* they have been through the Encoder which will determine what the message looks like in its wire representation. I don't see how you wrest control over the namespace prefixes from this... but by all means try, and please post an update if you find a way. – Chris Dickson Jun 29 '11 at 11:48

3 Answers3

2

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.

Cosmin Vană
  • 1,562
  • 12
  • 28
0

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

SaravananArumugam
  • 3,680
  • 6
  • 33
  • 45
  • 1
    Thanks but the Using message contracts means to have control over server side code. which I dont have. – activebiz Jun 29 '11 at 07:22
  • 1
    Need not be. As a whole, WCF is not a technology to write service. Its for communication. You can write WCF client for even non-WCF service. In your case, you can use WCF to create client and you can also make a point to create message contracts for your client side code. If you are using visual studio, the service reference dialog would provide you option to create Message Contracts under Advanced option. If you use svcutil.exe for creating the client, you can use /mc switch to create the message contract. – SaravananArumugam Jun 29 '11 at 13:26
0

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.

Chris Dickson
  • 11,964
  • 1
  • 39
  • 60