来自 .NET C# 客户端的 Java Web 服务 - 命名空间故障?
我们已经使用 Spring-WS 构建了一个 Web 服务,并尝试从 C# .NET 客户端访问它。该服务在我们从 SoapUI 和其他 Java 客户端完成的所有测试中工作正常,但在 .NET 中陷入困境。
看来这是命名空间的问题。
例如,当仅在信封标记中声明名称空间并且没有元素包含名称空间或前缀时,此请求有效:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://mycompany.org/schemas">
<soapenv:Header/>
<soapenv:Body>
<authenticationRequest>
<username>user</username>
<password>password</password>
</authenticationRequest>
</soapenv:Body>
</soapenv:Envelope>
但是,这个看似等效的请求不起作用:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://mycompany.org/schemas">
<soapenv:Header/>
<soapenv:Body>
<authenticationRequest xmlns="http://mycompany.org/schemas">
<username>user</username>
<password>password</password>
</authenticationRequest>
</soapenv:Body>
</soapenv:Envelope>
请注意,在这种情况下,名称空间再次在身份验证请求元素。 给出的错误是请求未根据 XML 模式进行验证,抱怨“用户名”元素未定义。
不幸的是,当在 .NET 中添加服务引用(以及 Web 引用)时,wsdl.exe 生成的代码总是在第二种情况下创建请求。
请有人解释一下为什么这两段 XML 不等效,以及我们如何在 C# 客户端中...
- 删除第二个命名空间声明?
- 或者为请求中的每个元素添加命名空间前缀?
- 或者添加一个没有前缀的命名空间声明到每个元素?
我们已经尝试了几个小时:(
谢谢!
We've built a webservice with Spring-WS, and are trying to access it from a C# .NET client. the service works OK with all the tests we've done from SoapUI and other java clients, but gets stuck in .NET.
It seems this is a problem with namespaces.
For example, this request works, when the namespace is declared only in the envelope tag, and no element has namespace or prefix in it:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://mycompany.org/schemas">
<soapenv:Header/>
<soapenv:Body>
<authenticationRequest>
<username>user</username>
<password>password</password>
</authenticationRequest>
</soapenv:Body>
</soapenv:Envelope>
However, this seemingly equivalent request does NOT work:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://mycompany.org/schemas">
<soapenv:Header/>
<soapenv:Body>
<authenticationRequest xmlns="http://mycompany.org/schemas">
<username>user</username>
<password>password</password>
</authenticationRequest>
</soapenv:Body>
</soapenv:Envelope>
Notice that in this case, the namespace is declared again in authenticationRequest element.
The error given is that the request does not validate against the XML schema, complaining that the 'username' element is not defined.
Unfortunately, when adding a service reference (and also a web reference) in .NET, the code generated by wsdl.exe always creates the request in the second case.
Could someone, please, explain why these two pieces of XML are not equivalent, and how we could, in the C# client...
- remove the second namespace declaration?
- or add a namespace prefix to every element in the request?
- or add a namespace declaration without prefix to each element?
We've been trying for hours :(
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在从 .NET 客户端访问 Java WS 时也遇到过类似的问题。我还没有找到解决该问题的优雅方法,但我确实通过使用 SoapExtension 更改传出/传入 SOAP 消息来解决它:
实现 SoapExtensionAttribute,如下所示:
实现 SoapExtension,如下所示:
I've had similar problems with accessing a Java WS from .NET client. I havent found an elegant solution to the problem, but I did solve it by changing the outgoing/incoming SOAP messages with a SoapExtension:
Implement a SoapExtensionAttribute, like this:
Implement a SoapExtension, like this: