我创建了soap webservice,在这个Web服务中我有add(int a, int b)
,它采用参数整数类型。
现在我的问题是如何通过使用java传递这些参数来使用此方法?如何使用java制作soap客户端?
WSDL
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://service.ss.com" xmlns:intf="http://service.ss.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.ss.com">
<!--
WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://service.ss.com">
<element name="add">
<complexType>
<sequence>
<element name="a" type="xsd:int"/>
<element name="b" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="addResponse">
<complexType>
<sequence>
<element name="addReturn" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="insert">
<complexType/>
</element>
<element name="insertResponse">
<complexType>
<sequence>
<element name="insertReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getDate">
<complexType/>
</element>
<element name="getDateResponse">
<complexType>
<sequence>
<element name="getDateReturn" type="xsd:dateTime"/>
</sequence>
</complexType>
</element>
<element name="findAll">
<complexType/>
</element>
<element name="findAllResponse">
<complexType>
<sequence>
<element name="findAllReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="insertRequest">
<wsdl:part element="impl:insert" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="addResponse">
<wsdl:part element="impl:addResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="findAllRequest">
<wsdl:part element="impl:findAll" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="addRequest">
<wsdl:part element="impl:add" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="getDateResponse">
<wsdl:part element="impl:getDateResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="insertResponse">
<wsdl:part element="impl:insertResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="getDateRequest">
<wsdl:part element="impl:getDate" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="findAllResponse">
<wsdl:part element="impl:findAllResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="TestService">
<wsdl:operation name="add">
<wsdl:input message="impl:addRequest" name="addRequest"></wsdl:input>
<wsdl:output message="impl:addResponse" name="addResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="insert">
<wsdl:input message="impl:insertRequest" name="insertRequest"></wsdl:input>
<wsdl:output message="impl:insertResponse" name="insertResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="getDate">
<wsdl:input message="impl:getDateRequest" name="getDateRequest"></wsdl:input>
<wsdl:output message="impl:getDateResponse" name="getDateResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAll">
<wsdl:input message="impl:findAllRequest" name="findAllRequest"></wsdl:input>
<wsdl:output message="impl:findAllResponse" name="findAllResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestServiceSoapBinding" type="impl:TestService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="add">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="addRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="addResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="insert">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="insertRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="insertResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getDate">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getDateRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getDateResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAll">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="findAllRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="findAllResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestServiceService">
<wsdl:port binding="impl:TestServiceSoapBinding" name="TestService">
<wsdlsoap:address location="http://localhost:8080/SoapService/services/TestService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
代码 这段代码运行良好,但我不知道如何传递参数。
String requestContent= "";
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://host.ubnsoft.com:8080/SoapService/services/TestService?wsdl");
WsdlInterface wsdl = wsdls[0];
List<Operation> operations = wsdl.getOperationList();
for (Operation operation : operations) {
WsdlOperation wsdlOperation = (WsdlOperation) operation;
// create a new empty request for that operation
WsdlRequest request = wsdlOperation.addNewRequest("My request");
request.setTimeout("2000");
requestContent = wsdlOperation.createRequest(true);
request.setRequestContent(requestContent);
System.out.println("REQUEST: " + requestContent);
// submit the request
try {
WsdlSubmit submit = (WsdlSubmit) request.submit(new WsdlSubmitContext(request), false);
Status status = submit.getStatus(); //FINISHED OR ERROR
System.out.println("STATUS: " + status);
Response response = submit.getResponse();
System.out.println("RESPONSE: " + response.getContentAsString());
} catch (SubmitException e) {
e.printStackTrace();
}
}
如何使用java发送带参数的请求并使用SOAP获取响应?