更改名称空间前缀WCF信封 [英] Change namespace Prefix WCF Envelope

查看:96
本文介绍了更改名称空间前缀WCF信封的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否仍然可以为WCF SOAP请求更改名称空间前缀?

I was wondering is there anyway to change the namespace prefix for the WCF SOAP request?

如下面的示例所示,信封的名称空间为"http://www.w3.org/2005/08/addressing",前缀为"a".我想将其更改为"foo".我怎样才能做到这一点. 注意,我无法控制服务代码,只能从WSDL创建代理类.

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>

推荐答案

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

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.

本文介绍了如何在服务器端使用MessageFormatter以及MessageEncoder的缺点:

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

您需要做的是应用MessageFormatter客户端(也许使用ApplyClientBehavior而不是ApplyDispatchBehavior).另外,在自定义消息类中,您需要添加名称空间作为属性,并带有"foo"前缀(在OnWriteStartEnvelope方法中).

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信封的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆