自定义 WCF 肥皂响应中的 xmlns:a= 标记
我正在创建一项服务来响应呼叫。 但是客户端(不是我写的)无法读取响应。 我们发现,这似乎是由于“
xmlns:a="http://schemas.datacontract.org/2004/07/MyProject.Classes"
是否有覆盖此命名空间?” 中的命名空间不匹配造成的。 我相当肯定是这样。
[ServiceBehavior] 标记具有“http:// Correctnamespace.com”命名空间
app.config 中的 BindingNameSpace 具有“http:// Correctnamespace.com”命名空间
[ServiceContract] 具有“http:// Correctnamespace.com” “ 命名空间
我查看了 OperationsContract 以查看是否可以找到它,但没有成功。
命名空间需要是“http:// Correctnamespace.com”
下面是 SOAP 响应上半部分的完整示例
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<getAddressResponse xmlns="http://correctnamespace.com">
<getAddressReturn xmlns:a="http://schemas.datacontract.org/2004/07/MyProject.Classes" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:PropertyChanged i:nil="true" xmlns:b="http://schemas.datacontract.org/2004/07/System.ComponentModel"/>
<a:addressField>Happystreet 21</a:addressField>
,我希望有人可以帮助我尽快对此进行排序。
添加信息
该服务是为了适合客户而创建的。
客户端是预先设计的,服务是根据客户端创建者提供的 WSDL 文件创建的。
另请注意,客户端无法修改。 :(
I'm creating a service to respond to calls.
However the client(not written by me) cannot read the response.
What we have located is that this seems to be due to th missmatching namespace in the
xmlns:a="http://schemas.datacontract.org/2004/07/MyProject.Classes"
Is there anyway to override this namespace?
I'm rather sure it is.
The [ServiceBehavior] tag has the "http://correctnamespace.com" NameSpace
The BindingNameSpace in the app.config has the "http://correctnamespace.com" Namespace
The [ServiceContract] has the "http://correctnamespace.com" Namespace
I've looked at the OperationsContract to see if I can locate it but without luck.
the namespace needs to be "http://correctnamespace.com"
Below is a full example of the Upper part of the SOAPresponse
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<getAddressResponse xmlns="http://correctnamespace.com">
<getAddressReturn xmlns:a="http://schemas.datacontract.org/2004/07/MyProject.Classes" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:PropertyChanged i:nil="true" xmlns:b="http://schemas.datacontract.org/2004/07/System.ComponentModel"/>
<a:addressField>Happystreet 21</a:addressField>
I hope someone can help me sort this ut ASAP.
Added information
The service is created to fit he client.
The client is predesigned and the service is created based on a WSDL file provided from the client creator.
Also note that the client cannot be modified. :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有几个建议。
首先,假设服务器端代码沙存根全部正确且运行正常,请要求客户端重新生成客户端存根。他们使用的存根可能是旧的或已被修改。
其次,如果服务器端也无法正常工作,我建议从头开始重新创建 WSDL。正确的 SOAP 编码是通过 WSDL 进行代码创建。因此,如果您的 WSDL 是由工具生成的,它将具有一定的命名约定,虽然您可以手动更改 xmlns 之类的内容,但如果您错过了其中一个(听起来就是这样),它就会弄乱您的代码。因此,返回并从头开始创建 WSDL,并从 WSDL 生成代码类,这样您就可以按照您希望的方式命名所有内容。
I have a couple suggestions.
First, assuming that the server side code sand stubs are all correct and functioning properly, ask the client to regen the client side stubs. It is possible that somehow the stub they are using is old or has been modified.
Second, if the serverside is also not working properly I recommend recreating your WSDL from scratch. Proper SOAP coding is WSDL to code creation. So if your WSDL was generated by a tool it will have a certain naming convention and while you can manually change things like your xmlns, if you miss one (which is what it sounds like happened) it will mess up your code. So go back and make the WSDL from scratch and generate the code classes from the WSDL that way you can name everything the way you want it to be named.
根据补充的信息,我再次有两个建议。
首先,您必须手动更改肥皂响应 AddressReturn 命名空间并遵循链,以便对上述响应的任何引用都具有正确的命名空间。这将是乏味且烦人的,但您可以编写一个 xml 解析器来查找对此类字段的任何引用,并在模式和 WSDL 中进行必要的更改。
其次,使用客户端提供给您的 WSDL 来创建您自己的 WSDL,该 WSDL 将与客户端一起使用,但具有您想要合并的命名约定。 WSDL 首次编码可以通过这种方式完成,有时也被推荐,因为它提供了您在创建和修改时遵循的框架,以使其成为您自己的并满足您的需求。
Based on the added information, I again have two suggestions.
First, is that you will have to go in and manually change the soap response AddressReturn namespace and follow the chain so that any references to the aforementioned response has the correct namespace. It will be tedious and annoying, but you could program an xml parser that can find any references to such field and make the necessary changes in both the schema and the WSDL.
Second is to use the WSDL provided to you by the client in order to create your own WSDL that will work with the client but has the naming conventions that you want incorporated. WSDL first coding can be done this way and is sometimes recommended because it provides the skeleton that you follow in creating and modifying to make it your own and fit your needs.
通过复制 WSDL 中的所有类并制作它们的 DataContracts 来解决,在这里可以像 ServiceContract 一样定义 NameSpace。
感谢每个花时间帮助我解决问题的人。
Solved by copying all the classed from the WSDL and made DataContracts of them instead, in this it's possible to define the NameSpace just like for the ServiceContract.
Thanks for evryone who took timeto help me solve his.