我想知道是否可以更改 WCF SOAP 请求的命名空间前缀?
正如您在下面的示例中看到的,The Envelope 的命名空间为“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 http://vanacosmin.ro/Articles/Read/WCFEnvelopeNamespacePrefix
您需要做的是应用 MessageFormatter 客户端(可能使用 ApplyClientBehavior 而不是 ApplyDispatchBehavior)。此外,在自定义消息类中,您需要添加名称空间作为属性,并带有“foo”前缀(在 OnWriteStartEnvelope 方法中)。
不幸的是,没有简单的方法(例如应用某些属性)来进行您需要的更改。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)