Eclipse使用axis1.4发布webservice服务

版权声明:本文为博主原创文章,转载请注明来源,谢谢。 https://blog.csdn.net/hkhhkb/article/details/80755829

一、wsdl文件

注:以下发布后的webservice服务并不能实现联通vac和sp对接。
1.1 联通规范中的wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tns3="http://rsp.sync.soap.bossagent.vac.unicom.com"
    xmlns:impl="http://soap.bossagent.vac.unicom.com" xmlns:intf="http://soap.bossagent.vac.unicom.com"
    xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:tns2="http://req.sync.soap.bossagent.vac.unicom.com" xmlns:tns4="http://type.sync.soap.bossagent.vac.unicom.com"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://soap.bossagent.vac.unicom.com">
    <wsdl:types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://req.sync.soap.bossagent.vac.unicom.com">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
            <complexType name="ArrayOf_tns2_SubInfo">
                <sequence>
                    <element maxOccurs="unbounded" minOccurs="1" name="item"
                        type="tns2:SubInfo" />
                </sequence>
            </complexType>
            <complexType name="OrderRelationUpdateNotifyRequest">
                <sequence>
                    <element name="recordSequenceId" nillable="true" type="soapenc:string" />
                    <element name="subNotify" type="tns2:ArrayOf_tns2_SubInfo" />
                </sequence>
            </complexType>
            <complexType name="SubInfo">
                <sequence>
                    <element name="userIdType" nillable="true" type="soapenc:int" />
                    <element name="userId" nillable="true" type="soapenc:string" />
                    <element name="serviceType" nillable="true" type="soapenc:string" />
                    <element name="spId" nillable="true" type="soapenc:string" />
                    <element name="sp_productId" nillable="true" type="soapenc:string" />
                    <element name="updateType" nillable="true" type="soapenc:int" />
                    <element name="updateTime" nillable="true" type="soapenc:string" />
                    <element name="updateDesc" nillable="true" type="soapenc:string" />
                    <element name="linkId" nillable="true" type="soapenc:string" />
                    <element name="content" nillable="true" type="soapenc:string" />
                    <element name="effectiveDate" nillable="true" type="soapenc:string" />
                    <element name="expireDate" nillable="true" type="soapenc:string" />
                    <element name="time_stamp" nillable="true" type="soapenc:string" />
                    <element name="encodeStr" nillable="true" type="soapenc:string" />
                    <element name="accessNo" nillable="true" type="soapenc:string" />
                </sequence>
            </complexType>
        </schema>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://rsp.sync.soap.bossagent.vac.unicom.com">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
            <complexType name="OrderRelationUpdateNotifyResponse">
                <sequence>
                    <element name="recordSequenceId" nillable="true" type="soapenc:string" />
                    <element name="resultCode" type="xsd:int" />
                </sequence>
            </complexType>
        </schema>
    </wsdl:types>
    <wsdl:message name="orderRelationUpdateNotifyRequest">
        <wsdl:part name="orderRelationUpdateNotifyRequest" type="tns2:OrderRelationUpdateNotifyRequest" />
    </wsdl:message>
    <wsdl:message name="orderRelationUpdateNotifyResponse">
        <wsdl:part name="orderRelationUpdateNotifyReturn" type="tns3:OrderRelationUpdateNotifyResponse" />
    </wsdl:message>
    <wsdl:portType name="SyncNotifySPService">
        <wsdl:operation name="orderRelationUpdateNotify"
            parameterOrder="orderRelationUpdateNotifyRequest">
            <wsdl:input name="orderRelationUpdateNotifyRequest"
                message="impl:orderRelationUpdateNotifyRequest" />
            <wsdl:output name="orderRelationUpdateNotifyResponse"
                message="impl:orderRelationUpdateNotifyResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="SyncNotifySPSoapBinding" type="impl:SyncNotifySPService">
        <wsdlsoap:binding style="rpc"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="orderRelationUpdateNotify">
            <wsdlsoap:operation />
            <wsdl:input>
                <wsdlsoap:body use="encoded"
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="http://soap.bossagent.vac.unicom.com" />
            </wsdl:input>
            <wsdl:output>
                <wsdlsoap:body use="encoded"
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="http://soap.bossagent.vac.unicom.com" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="SyncNotifySPServiceService">
        <wsdl:port name="SyncNotifySP" binding="impl:SyncNotifySPSoapBinding">
            <wsdlsoap:address location="http://localhost/services/VacSync" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
1.2 修改后的wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tns3="http://rsp.sync.soap.bossagent.vac.unicom.com"
    xmlns:impl="http://soap.bossagent.vac.unicom.com" xmlns:intf="http://soap.bossagent.vac.unicom.com"
    xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:tns2="http://req.sync.soap.bossagent.vac.unicom.com" xmlns:tns4="http://type.sync.soap.bossagent.vac.unicom.com"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://soap.bossagent.vac.unicom.com">
    <wsdl:types>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://req.sync.soap.bossagent.vac.unicom.com">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
            <complexType name="OrderRelationUpdateNotifyRequest">
                <sequence>
                    <element name="recordSequenceId" nillable="true" type="soapenc:string" />
                    <element name="userIdType" nillable="true" type="soapenc:int" />
                    <element name="userId" nillable="true" type="soapenc:string" />
                    <element name="serviceType" nillable="true" type="soapenc:string" />
                    <element name="spId" nillable="true" type="soapenc:string" />
                    <element name="productId" nillable="true" type="soapenc:string" />
                    <element name="updateType" nillable="true" type="soapenc:int" />
                    <element name="updateTime" nillable="true" type="soapenc:string" />
                    <element name="updateDesc" nillable="true" type="soapenc:string" />
                    <element name="linkId" nillable="true" type="soapenc:string" />
                    <element name="content" nillable="true" type="soapenc:string" />
                    <element name="effectiveDate" nillable="true" type="soapenc:string" />
                    <element name="expireDate" nillable="true" type="soapenc:string" />
                    <element name="time_stamp" nillable="true" type="soapenc:string" />
                    <element name="encodeStr" nillable="true" type="soapenc:string" />
                </sequence>
            </complexType>
        </schema>
        <schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://rsp.sync.soap.bossagent.vac.unicom.com">
            <import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
            <complexType name="OrderRelationUpdateNotifyResponse">
                <sequence>
                    <element name="recordSequenceId" nillable="true" type="soapenc:string" />
                    <element name="resultCode" type="xsd:int" />
                </sequence>
            </complexType>
        </schema>
    </wsdl:types>
    <wsdl:message name="orderRelationUpdateNotifyRequest">
        <wsdl:part name="orderRelationUpdateNotifyRequest" type="tns2:OrderRelationUpdateNotifyRequest" />
    </wsdl:message>
    <wsdl:message name="orderRelationUpdateNotifyResponse">
        <wsdl:part name="orderRelationUpdateNotifyReturn" type="tns3:OrderRelationUpdateNotifyResponse" />
    </wsdl:message>
    <wsdl:portType name="SyncNotifySPService">
        <wsdl:operation name="orderRelationUpdateNotify"
            parameterOrder="orderRelationUpdateNotifyRequest">
            <wsdl:input name="orderRelationUpdateNotifyRequest"
                message="impl:orderRelationUpdateNotifyRequest" />
            <wsdl:output name="orderRelationUpdateNotifyResponse"
                message="impl:orderRelationUpdateNotifyResponse" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="SyncNotifySPSoapBinding" type="impl:SyncNotifySPService">
        <wsdlsoap:binding style="rpc"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="orderRelationUpdateNotify">
            <wsdlsoap:operation />
            <wsdl:input>
                <wsdlsoap:body use="encoded"
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="http://soap.bossagent.vac.unicom.com" />
            </wsdl:input>
            <wsdl:output>
                <wsdlsoap:body use="encoded"
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="http://soap.bossagent.vac.unicom.com" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="SyncNotifySPServiceService">
        <wsdl:port name="SyncNotifySP" binding="impl:SyncNotifySPSoapBinding">
            <wsdlsoap:address location="http://localhost/services/VacSync" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

二、新建java web项目

2.1 axis1.4依赖如下(这里暂不使用)
<dependencies>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis-wsdl4j</artifactId>
        <version>1.5.1</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
</dependencies>
2.2 复制修改后的wsdl文件

这里写图片描述

2.3 右键wsdl文件生成代码

这里写图片描述
这里写图片描述

2.4 复制deploy.wsdd和undeploy.wsdd,删除多余的文件和目录

这里写图片描述
这里写图片描述

2.5 启动项目,并在浏览器输入:http://localhost:8080/ws/services

这里写图片描述

2.6 cd到WEB-INF目录,输入如下命令:
java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -l http://localhost:8080/ws/services/AdminService deploy.wsdd

这里写图片描述

2.7 刷新java web项目,并删掉deploy.wsdd和undeploy.wsdd,修改server-config.wsdd并重启项目

这里写图片描述

server-config.wsdd修改为
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <globalConfiguration>
        <parameter name="sendMultiRefs" value="true" />
        <parameter name="disablePrettyXML" value="true" />
        <parameter name="adminPassword" value="admin" />
        <parameter name="dotNetSoapEncFix" value="true" />
        <parameter name="enableNamespacePrefixOptimization" value="false" />
        <parameter name="sendXMLDeclaration" value="true" />
        <parameter name="sendXsiTypes" value="true" />
        <parameter name="attachments.implementation"
            value="org.apache.axis.attachments.AttachmentsImpl" />
        <requestFlow>
            <handler type="java:org.apache.axis.handlers.JWSHandler">
                <parameter name="scope" value="session" />
            </handler>
            <handler type="java:org.apache.axis.handlers.JWSHandler">
                <parameter name="scope" value="request" />
                <parameter name="extension" value=".jwr" />
            </handler>
        </requestFlow>
    </globalConfiguration>
    <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
    <handler name="Authenticate"
        type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
    <handler name="LocalResponder"
        type="java:org.apache.axis.transport.local.LocalResponder" />
    <transport name="http">
        <requestFlow>
            <handler type="URLMapper" />
            <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
        </requestFlow>
        <parameter name="qs:list"
            value="org.apache.axis.transport.http.QSListHandler" />
        <parameter name="qs:wsdl"
            value="org.apache.axis.transport.http.QSWSDLHandler" />
        <parameter name="qs.list"
            value="org.apache.axis.transport.http.QSListHandler" />
        <parameter name="qs.method"
            value="org.apache.axis.transport.http.QSMethodHandler" />
        <parameter name="qs:method"
            value="org.apache.axis.transport.http.QSMethodHandler" />
        <parameter name="qs.wsdl"
            value="org.apache.axis.transport.http.QSWSDLHandler" />
    </transport>
    <transport name="local">
        <responseFlow>
            <handler type="LocalResponder" />
        </responseFlow>
    </transport>

    <!-- <service name="AdminService" provider="java:MSG"> -->
    <!-- <parameter name="allowedMethods" value="AdminService" /> -->
    <!-- <parameter name="enableRemoteAdmin" value="false" /> -->
    <!-- <parameter name="className" value="org.apache.axis.utils.Admin" /> -->
    <!-- <namespace>http://xml.apache.org/axis/wsdd/</namespace> -->
    <!-- </service> -->
    <!-- <service name="Version" provider="java:RPC"> -->
    <!-- <parameter name="allowedMethods" value="getVersion" /> -->
    <!-- <parameter name="className" value="org.apache.axis.Version" /> -->
    <!-- </service> -->
    <service name="vac" provider="java:RPC">
        <parameter name="allowedMethods" value="*" />
        <parameter name="typeMappingVersion" value="1.2" />
        <parameter name="wsdlPortType" value="SyncNotifySPService" />
        <parameter name="className"
            value="com.unicom.vac.bossagent.soap.SyncNotifySPSoapBindingSkeleton" />
        <parameter name="wsdlServicePort" value="SyncNotifySP" />
        <parameter name="wsdlTargetNamespace" value="http://soap.bossagent.vac.unicom.com" />
        <parameter name="wsdlServiceElement" value="SyncNotifySPServiceService" />
        <parameter name="schemaUnqualified"
            value="http://rsp.sync.soap.bossagent.vac.unicom.com,http://req.sync.soap.bossagent.vac.unicom.com" />
        <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" qname="ns1:OrderRelationUpdateNotifyResponse"
            serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
            type="java:com.unicom.vac.bossagent.soap.sync.rsp.OrderRelationUpdateNotifyResponse"
            xmlns:ns1="http://rsp.sync.soap.bossagent.vac.unicom.com" />
        <typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" qname="ns2:OrderRelationUpdateNotifyRequest"
            serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
            type="java:com.unicom.vac.bossagent.soap.sync.req.OrderRelationUpdateNotifyRequest"
            xmlns:ns2="http://req.sync.soap.bossagent.vac.unicom.com" />
    </service>
</deployment>
输入地址:http://localhost:8080/ws/services/vac?wsdl

这里写图片描述

2.8 业务逻辑需在SyncNotifySPSoapBindingImpl.java处理

三、客户端调用

3.1 新建java web项目,把上面的xml另存为wsdl文件,并复制到项目里

这里写图片描述

3.2 右键wsdl文件生成客户端调用代码

这里写图片描述
这里写图片描述

3.3 新建TestClient类
public class TestClient {

    public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException {
        String wsdl = "http://localhost:8080/ws/services/vac?wsdl";
        Service service = new Service();
        SyncNotifySPSoapBindingStub stub = new SyncNotifySPSoapBindingStub(new java.net.URL(wsdl), service);
        OrderRelationUpdateNotifyRequest request = new OrderRelationUpdateNotifyRequest();
        request.setSpId("123");
        request.setContent("调用");
        OrderRelationUpdateNotifyResponse response = stub.orderRelationUpdateNotify(request);
        System.out.println(response.getRecordSequenceId());
        System.out.println(response.getResultCode());
    }

}
3.4 运行TestClient类测试

这里写图片描述

四、完整代码

下载地址:联通vac服务端和客户端源码
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页