Wsdl2java generates Java Service interfaces through WSDL files and implements

Source: Internet
Author: User

1, first find a WSDL file, you can go to copy

<?xml version= "1.0" encoding= "UTF-8"?>

<wsdl:definitions targetnamespace= "Http://address.jaxrpc.samples" xmlns= "http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap= "Http://xml.apache.org/xml-soap" xmlns:impl= "Http://address.jaxrpc.samples" xmlns:intf= "http://" Address.jaxrpc.samples "xmlns:soapenc=" http://schemas.xmlsoap.org/soap/encoding/"xmlns:wsdl=" http:// schemas.xmlsoap.org/wsdl/"xmlns:wsdlsoap=" http://schemas.xmlsoap.org/wsdl/soap/"xmlns:xsd=" http://www.w3.org/ 2001/xmlschema ">

<wsdl:types>

<schema targetnamespace= "Http://address.jaxrpc.samples" xmlns= "Http://www.w3.org/2001/XMLSchema" >

<import namespace= "http://schemas.xmlsoap.org/soap/encoding/"/>

<complextype name= "Addressbean" >

<sequence>

<element name= "Street" nillable= "true" type= "xsd:string"/>

<element name= "postcode" type= "Xsd:int"/>

</sequence>

</complexType>

<element name= "Addressbean" nillable= "true" type= "Impl:addressbean"/>

</schema>

<schema targetnamespace= "Http://www.w3.org/2001/XMLSchema" xmlns= "Http://www.w3.org/2001/XMLSchema" >

<import namespace= "http://schemas.xmlsoap.org/soap/encoding/"/>

<element name= "int" type= "Xsd:int"/>

<element name= "string" type= "Xsd:string"/>

</schema>

</wsdl:types>

<wsdl:message name= "Updateaddressrequest" >

<wsdl:part name= "In0" type= "Intf:addressbean"/>

<wsdl:part name= "in1" type= "Xsd:int"/>

</wsdl:message>

<wsdl:message name= "Updateaddressresponse" >

<wsdl:part name= "return" type= "xsd:string"/>

</wsdl:message>

<wsdl:porttype name= "Addressservice" >

<wsdl:operation name= "updateaddress" parameterorder= "In0 in1" >

<wsdl:input message= "Intf:updateaddressrequest" name= "Updateaddressrequest"/>

<wsdl:output message= "Intf:updateaddressresponse" name= "Updateaddressresponse"/>

</wsdl:operation>

</wsdl:portType>

<wsdl:binding name= "addresssoapbinding" type= "Intf:addressservice" >

<wsdlsoap:binding style= "rpc" transport= "Http://schemas.xmlsoap.org/soap/http"/>

<wsdl:operation name= "Updateaddress" >

<wsdlsoap:operation soapaction= ""/>

<wsdl:input name= "Updateaddressrequest" >

<wsdlsoap:body encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" namespace= "http:// Address.jaxrpc.samples "use=" encoded "/>

</wsdl:input>

<wsdl:output name= "Updateaddressresponse" >

<wsdlsoap:body encodingstyle= "http://schemas.xmlsoap.org/soap/encoding/" namespace= "http:// Address.jaxrpc.samples "use=" encoded "/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service name= "Addressserviceservice" >

<wsdl:port binding= "intf:addresssoapbinding" name= "Address" >

<wsdlsoap:address location= "Http://localhost:8080/MyAxisPoJoWebService/services/Address"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

To use the command:

-P (Specify package)-0 (specified directory)-V (Display information)--server-side (build server bindings (can not))--skeletondeploy true WSDL file

-v-p cn.com.test.webservice.service-o src--server-side

address.wsdl

Some classes and files are generated

Add--skeletondeploy True to specify that the implementation class is a deployment class, with one more Addresssoapbindingskeleton.java

--skeletiondeploy true: Can be understood to be deployed to a built skeleton

Then the service method in the ADDRESSSOAPBINDINGINPL is implemented manually, and uploaded to the server via DEPLOY.WSDD

/**

* Addresssoapbindingimpl.java

*

* This file is auto-generated from WSDL

* by the Apache Axis 1.4 Apr, 2006 (06:55:48 PDT) Wsdl2java emitter.

*/

Package cn.com.test.webservice.service;

public class Addresssoapbindingimpl implements cn.com.test.webservice.service.addressservice{

Public java.lang.String updateaddress (cn.com.test.webservice.service.AddressBean in0, int in1) throws java.rmi.RemoteException {

Return "Test returned data";

}

}

Finally, all the generated Java files are copied to the server side of the same directory, but also appropriate to see what not to delete

Test:

/*

* Copyright 2001-2004 the Apache Software Foundation.

*

* Licensed under the Apache License, Version 2.0 (the "License");

* You could not use this file, except in compliance with the License.

* Obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable or agreed to in writing, software

* Distributed under the License is distributed on ' as ' basis,

* Without warranties or CONDITIONS of any KIND, either express or implied.

* The License for the specific language governing permissions and

* Limitations under the License.

*/

Package cn.com.test.webservice;

Import java.rmi.RemoteException;

Import javax.xml.rpc.ServiceException;

Import Cn.com.test.webservice.service.AddressBean;

Import Cn.com.test.webservice.service.AddressService;

Import Cn.com.test.webservice.service.AddressServiceServiceLocator;

public class Client03

{

public static void Main (String [] args) throws Serviceexception, RemoteException

{

Addressservice service= New Addressserviceservicelocator (). getaddress ();

System.out.println ("John" +service.updateaddress (New Addressbean (), 2));

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.