使用JDK6自带的webService发布一个ws:@WebMethod
@WebResult(partName="getWeatherReturn")
public String getWeather(String name){
return name+"123";
}发布Endpoint.publish("http://localhost:8020/weather", new HelloService());使用JDK自己工具生成的客户端能正确使用该ws。
生成的wsdl:<?xml version="1.0" encoding="UTF-8" standalone="yes"?><definitions targetNamespace="http://service.ws.stef.com/" name="WeatherServiceService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.ws.stef.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://service.ws.stef.com/" schemaLocation="WeatherServiceService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getWeather">
<part name="parameters" element="tns:getWeather"/>
</message>
<message name="getWeatherResponse">
<part name="parameters" element="tns:getWeatherResponse"/>
</message>
<portType name="WeatherService">
<operation name="getWeather">
<input message="tns:getWeather"/>
<output message="tns:getWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherServicePortBinding" type="tns:WeatherService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getWeather">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WeatherServiceService">
<port name="WeatherServicePort" binding="tns:WeatherServicePortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
但是我换成axis1.4
客户端关键代码:Service s=new Service();
Call c=(Call)s.createCall();
c.setTargetEndpointAddress(new URL("http://localhost:8030/weather"));
c.setOperationName(new QName("http://service.ws.stef.com/","getWeather"));
c.addParameter("arg0",Constants.XSD_STRING, ParameterMode.IN);c.setReturnType(Constants.XSD_INTEGER);
Object o=c.invoke(new Object[]{"hello"});
System.out.println(o);在TCPmon中监控到的请求是:<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getWeather soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://service.ws.stef.com/">
<arg0 xsi:type="xsd:string">hello</arg0>
</ns1:getWeather>
</soapenv:Body>
</soapenv:Envelope>返回是:<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getWeatherResponse xmlns:ns2="http://service.ws.stef.com/">
<getWeatherReturn>hello123</getWeatherReturn>
</ns2:getWeatherResponse>
</S:Body>
</S:Envelope>
说明是正确返回了的。
但是就是停在解析这个response的那个方法调用上,就执行不下去了。感觉测试线程就挂起了。不知道怎么回事的。
网上找了很久也没有相关的资料。虽然JDK自带的WebService还不稳定,只能是个玩具,但是我确实对这个问题想不通,求解。谢谢~~
@WebResult(partName="getWeatherReturn")
public String getWeather(String name){
return name+"123";
}发布Endpoint.publish("http://localhost:8020/weather", new HelloService());使用JDK自己工具生成的客户端能正确使用该ws。
生成的wsdl:<?xml version="1.0" encoding="UTF-8" standalone="yes"?><definitions targetNamespace="http://service.ws.stef.com/" name="WeatherServiceService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.ws.stef.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://service.ws.stef.com/" schemaLocation="WeatherServiceService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getWeather">
<part name="parameters" element="tns:getWeather"/>
</message>
<message name="getWeatherResponse">
<part name="parameters" element="tns:getWeatherResponse"/>
</message>
<portType name="WeatherService">
<operation name="getWeather">
<input message="tns:getWeather"/>
<output message="tns:getWeatherResponse"/>
</operation>
</portType>
<binding name="WeatherServicePortBinding" type="tns:WeatherService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getWeather">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WeatherServiceService">
<port name="WeatherServicePort" binding="tns:WeatherServicePortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
但是我换成axis1.4
客户端关键代码:Service s=new Service();
Call c=(Call)s.createCall();
c.setTargetEndpointAddress(new URL("http://localhost:8030/weather"));
c.setOperationName(new QName("http://service.ws.stef.com/","getWeather"));
c.addParameter("arg0",Constants.XSD_STRING, ParameterMode.IN);c.setReturnType(Constants.XSD_INTEGER);
Object o=c.invoke(new Object[]{"hello"});
System.out.println(o);在TCPmon中监控到的请求是:<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getWeather soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://service.ws.stef.com/">
<arg0 xsi:type="xsd:string">hello</arg0>
</ns1:getWeather>
</soapenv:Body>
</soapenv:Envelope>返回是:<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getWeatherResponse xmlns:ns2="http://service.ws.stef.com/">
<getWeatherReturn>hello123</getWeatherReturn>
</ns2:getWeatherResponse>
</S:Body>
</S:Envelope>
说明是正确返回了的。
但是就是停在解析这个response的那个方法调用上,就执行不下去了。感觉测试线程就挂起了。不知道怎么回事的。
网上找了很久也没有相关的资料。虽然JDK自带的WebService还不稳定,只能是个玩具,但是我确实对这个问题想不通,求解。谢谢~~
疑问又来了。。
通过debug的方式,我居然每次都能得到正确的答案。。说明这个客户端调用方式应该是没有问题的。但是直接运行,就是线程挂起。。但具体挂起在什么地方,我确实找不到。因为debug是对的。这是为什么?有耐心和经验的帮我解释这个问题么?我只是想知道造成这个问题的根本原因。谢谢。