我用JAVA编写的SOAP服务器有问题,该项目作为Windows服务而不是作为Web服务器(例如GLASSFISH)运行。所以问题是,每次我从C#.NET客户端发出请求时,JAVA SOAP服务器都无法解析该请求。被调用的函数获取一个NULL值作为输入参数。
与JAVA客户,SoapUI和aso的通信。我可以正常工作,但是.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。
(例如ServiceReference)
TestService.WSClient proxy = new TestService.WSClient();
String results = proxy.echo("TEST");
有人可以告诉我如何使JAVA服务器与.NET请求兼容吗?感谢帮助!
您正在使用Java JDK 1.8吗?因为我不认为C#.NET正在发送该参数的名称空间,但是它正在发送一个空的名称空间,如下所示:
<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="">TEST</val>
</echo>
</s:Body>
</s:Envelope>
Java JDK 1.8包含带有错误的JAX-WS版本。就像上面的C#示例一样,将完全错误地解析C#客户端请求的空名称空间。
尝试使用最新版本的> JAX-WS <。
>这里<,您可以找到有关如何实现库的描述。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句