第一步:
根据WSDL生成对应的请求,应答报文对象,service,porttype对象。(用myEclipse自带的工具或者jdk自带的命令)
对应的类如下:
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.1 in JDK 6
* Generated source version: 2.1
*
*/
@WebServiceClient(name = "SampleService", targetNamespace = "http://xx/service", wsdlLocation = "file:/F:/file/test.wsdl")
public class SampleService
extends Service
{
private final static URL SampleService_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("file:/F:/file/test.wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
SampleService_WSDL_LOCATION = url;
}
public SampleService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public SampleService() {
super(SampleService_WSDL_LOCATION, new QName("http://xx/service", "SampleService"));
}
/**
*
* @return
* returns NodeHscResetServicePortType
*/
@WebEndpoint(name = "SampleServicePort")
public SampleServicePortType getSampleServicePort() {
return (SampleServicePortType)super.getPort(new QName("http://xx/service", "SampleServicePort"), SampleServicePortType.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns NodeHscResetServicePortType
*/
@WebEndpoint(name = "SampleServicePort")
public SampleServicePortType getSampleServicePort(WebServiceFeature... features) {
return (SampleServicePortType)super.getPort(new QName("http://xx/service", "SampleServicePort"), SampleServicePortType.class, features);
}
}
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.1 in JDK 6
* Generated source version: 2.1
*
*/
@WebService(name = "SampleServicePortType", targetNamespace = "http://xx/service")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
ObjectFactory.class
})
public interface SampleServicePortType {
@WebMethod(action = "testQry")
@WebResult(name = "TestQryResponse", targetNamespace = "http://xx/service", partName = "TestQryResponseMessage")
public TestQryResponse testQry(
@WebParam(name = "TestQryRequest", targetNamespace = "http://xx/service", partName = "TestRequestMessage")
TestQryRequest testQryRequestMessage);
}
}
第二步:调用服务
String targetNamespace = "http://xx/service";
String serName ="SampleService";
URL wsdlLocation = new URL(http://xx/test.wsdl);
QName serviceName = new QName(targetNamespace, serName);
SampleService service = new SampleService(wsdlLocation,serviceName);
SampleServicePortType port = service.getSampleServicePort();
BindingProvider bpPort = (BindingProvider) port;
bpPort.getRequestContext().put("com.sun.xml.ws.request.timeout", "10000"); // 设置查询超时时间
//设置请求对象request的值,本处省掉
SampleServiceResponse response = port.testQry(request);