更改名称空间前缀WCF信封

我想知道是否有更改WCF SOAP请求的名称空间前缀?

正如您在下面的示例中所看到的,信封的名称空间为“http://www.w3.org/2005/08/addressing”,前缀为“a”.我想把它改成’foo’.我怎样才能做到这一点.
注意我无法控制服务代码我只能从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>

最佳答案 这可以通过使用MessageFormatter在客户端或服务器端完成.您也可以使用MessageEncoder更改此设置,但这有很多问题.

本文介绍如何使用MessageFormatter在服务器端执行此操作,以及MessageEncoder的缺点:

http://vanacosmin.ro/Articles/Read/WCFEnvelopeNamespacePrefix

您需要做的是应用MessageFormatter客户端(可能使用ApplyClientBehavior而不是ApplyDispatchBehavior).此外,在自定义消息类中,您需要将名称空间添加为属性,使用“foo”前缀(在OnWriteStartEnvelope方法中).

不幸的是,没有简单的方法(比如应用一些属性)可以进行所需的更改.

点赞