webservice wsdl接口配置与调用

准备包

WebRoot/WEB-INF/lib/axis2-adb-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-ant-plugin-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-clustering-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-codegen-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-corba-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-fastinfoset-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-java2wsdl-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-jaxbri-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-jaxws-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-jibx-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-json-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-kernel-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-metadata-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-mtompolicy-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-saaj-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-spring-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-transport-http-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-transport-local-1.6.2.jar
WebRoot/WEB-INF/lib/axis2-xmlbeans-1.6.2.jar

WebRoot/WEB-INF/lib/wstx-asl-3.2.9.jar

WSDL 接口java文件

package com.neusoft.ermsuite.css.ws.svac.bangjia;

public class BangJiaOrder {

    public String doService(String aa){
System.out.println(aa);
return aa;
}
}

service.xml配置接口描述

<service name="BangJiaOrder">
<description>
BangJiaOrder
</description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
<parameter name="ServiceClass">com.neusoft.ermsuite.css.ws.svac.bangjia.BangJiaOrder
</parameter>
</service>

启动tomcat,输入查看接口是否发布成功

http://localhost:8080/项目名/services/BangJiaOrder?wsdl

成功后有下面xml显示

  <?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://bangjia.svac.ws.css.ermsuite.neusoft.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://bangjia.svac.ws.css.ermsuite.neusoft.com">
<wsdl:documentation>BangJiaOrder</wsdl:documentation>
- <wsdl:types>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://bangjia.svac.ws.css.ermsuite.neusoft.com">
- <xs:element name="doService">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="aa" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="doServiceResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
- <wsdl:message name="doServiceRequest">
<wsdl:part name="parameters" element="ns:doService" />
</wsdl:message>
- <wsdl:message name="doServiceResponse">
<wsdl:part name="parameters" element="ns:doServiceResponse" />
</wsdl:message>
- <wsdl:portType name="BangJiaOrderPortType">
- <wsdl:operation name="doService">
<wsdl:input message="ns:doServiceRequest" wsaw:Action="urn:doService" />
<wsdl:output message="ns:doServiceResponse" wsaw:Action="urn:doServiceResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="BangJiaOrderSoap11Binding" type="ns:BangJiaOrderPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="doService">
<soap:operation soapAction="urn:doService" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="BangJiaOrderSoap12Binding" type="ns:BangJiaOrderPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="doService">
<soap12:operation soapAction="urn:doService" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="BangJiaOrderHttpBinding" type="ns:BangJiaOrderPortType">
<http:binding verb="POST" />
- <wsdl:operation name="doService">
<http:operation location="doService" />
- <wsdl:input>
<mime:content type="application/xml" part="parameters" />
</wsdl:input>
- <wsdl:output>
<mime:content type="application/xml" part="parameters" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="BangJiaOrder">
- <wsdl:port name="BangJiaOrderHttpSoap11Endpoint" binding="ns:BangJiaOrderSoap11Binding">
<soap:address location="http://localhost:8080/项目名/services/BangJiaOrder.BangJiaOrderHttpSoap11Endpoint/" />
</wsdl:port>
- <wsdl:port name="BangJiaOrderHttpSoap12Endpoint" binding="ns:BangJiaOrderSoap12Binding">
<soap12:address location="http://localhost:8080/项目名/services/BangJiaOrder.BangJiaOrderHttpSoap12Endpoint/" />
</wsdl:port>
- <wsdl:port name="BangJiaOrderHttpEndpoint" binding="ns:BangJiaOrderHttpBinding">
<http:address location="http://localhost:8080/项目名/services/BangJiaOrder.BangJiaOrderHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

调用webservice wsdl

package com.neusoft.ermsuite.css.sv.svac.svrequest.bo;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient; public class test { public static void main(String[] args) throws AxisFault {
// 使用RPC方式调用WebService
RPCServiceClient sc = new RPCServiceClient();
Options options = sc.getOptions(); // 指定调用WebService的URL
EndpointReference targetErp = new EndpointReference("http://localhost:8080/项目名/services/BangJiaOrder");
options.setTo(targetErp); // 指定getGreeting方法的参数值
Object[] opAddEntryArgs = new Object[] { "Test 1.0" }; // 指定doService方法返回值的数据类型的Class对象
Class[] classes = new Class[] { String.class }; // 指定要调用的doService方法及WSDL文件的命名空间
QName opAddEntry = new QName("http://bangjia.svac.ws.css.ermsuite.neusoft.com", "doService");

      sc.getOptions().setTimeOutInMilliSeconds(600000L);
// 调用doService方法并输出该方法的返回值
System.out.println(sc.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);
// 下面是调用getPrice 方法的代码,这些代码与调用getGreeting方法的代码类似
// classes = new Class[] {int.class};
// opAddEntry = new QName("http://ws.apache.org/axis2", "getPrice");
// System.out.println(sc.invokeBlocking(opAddEntry, new Object[] {}, classes)[0]); }
}
QName opAddEntry = new QName("http://bangjia.svac.ws.css.ermsuite.neusoft.com", "doService");
注意
"http://bangjia.svac.ws.css.ermsuite.neusoft.com"是在浏览器查看xml时可以看到的
targetNamespace="http://bangjia.svac.ws.css.ermsuite.neusoft.com"
上一篇:Javascript 获取窗口的大小和位置


下一篇:spark第六次课