【发布时间】:2014-12-09 08:40:31
【问题描述】:
我有一个用 JAVA 编写的 SOAP 服务器的问题,该项目作为 Windows 服务而不是作为 Web 服务器运行(例如 GLASSFISH)。 所以问题是,每次我从 C# .NET 客户端发出请求时,JAVA SOAP 服务器都无法解析请求。被调用的函数获取一个NULL值作为输入参数。
与 JAVA 客户端、SoapUI 等的通信。工作完美,但我认为 .NET (C#) 客户端正在发送恶意请求。因为该项目已经存在并安装了很多次,所以我无法用 C# 开发它。 我已经阅读了很多类似问题的线程,但我找不到任何适合我的情况的解决方案。
我只是写了一些简单的测试用例来简短地向您展示问题。
JAVA 代码:
main.java
//...
Endpoint endpoint = Endpoint.create(new WS());
endpoint.publish("http://0.0.0.0:8081/test");
//...
WS.java
//...
@WebService(serviceName = "WS")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class WS {
@WebMethod(operationName = "echo")
public String echo(@WebParam(name = "val") String val) {
return val;
}
}
WSDL:
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webj/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webj/" name="WS">
<types/>
<message name="echo">
<part name="val" type="xsd:string"/>
</message>
<message name="echoResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="WS">
<operation name="echo">
<input wsam:Action="http://webj/WS/echoRequest" message="tns:echo"/>
<output wsam:Action="http://webj/WS/echoResponse" message="tns:echoResponse"/>
</operation>
</portType>
<binding name="WSPortBinding" type="tns:WS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="echo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://webj/"/>
</input>
<output>
<soap:body use="literal" namespace="http://webj/"/>
</output>
</operation>
</binding>
<service name="WS">
<port name="WSPort" binding="tns:WSPortBinding">
<soap:address location="http://xxx:8081/test"/>
</port>
</service>
C# 请求
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<s:Body>
<echo xmlns="http://webj/">
<val xmlns="http://webj/">TEST</val>
</echo>
</s:Body>
</s:Envelope>
JAVA 请求
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:std="http://webj/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<std:echo>
<val>TEST</val>
</std:echo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
问题似乎是参数“val”的命名空间:
<echo xmlns="http://webj/">
<val xmlns="http://webj/">TEST</val>
</echo>
我已经在 JAVA 中通过手动向参数“val”添加命名空间来测试这种情况,并遇到了同样的问题。在 C# 中,我尝试使用生成的 WebReferences 和 ServiceReferences。
(例如服务参考)
TestService.WSClient proxy = new TestService.WSClient();
String results = proxy.echo("TEST");
谁能告诉我如何获得兼容 .NET 请求的 JAVA 服务器? 感谢您的帮助!
【问题讨论】:
-
使用 SoapUI 作为模型服务器,并亲自查看您的 C# 代码发送的内容。
-
@JIV C# 正在发送上述“C# 请求”(我已经在 JAVA 端记录了传输)
-
那么来自 C# 的请求在 SoapUI 中有效吗?
-
不,从 SoapUI 发送的 C# 请求也会失败。但是,如果我将 C# 请求从 .NET 应用程序发送到从 java wsdl 创建的 SoapUI 模拟服务,它就可以工作!