Use Java 6 as the WebService Client

Source: Internet
Author: User
Tags wsdl

In the previous blog post, we introduced how to run wervice using the built-in server of java 6. Then, the client of the released Service is generated.

We only need to use wsimport to generate client code.

Enter wsimport-keep-p com. geostar. geoglobe. jaxws. client http: // 126.33.8.183: 9999/GeoGlobeServer? Wsdl

Click Enter to generate the client code for us immediately. The GeoGlobeServer. java, ObjectFactory. java, and WSDemo. java classes are generated under the com. geostar. geoglobe. jaxws directory.

Next, let's take a look at what these classes do.

// GeoGlobeServer. java

Import java.net. MalformedURLException;
Import java.net. URL;
Import javax. xml. namespace. QName;
Import javax. xml. ws. Service;
Import javax. xml. ws. WebEndpoint;
Import javax. xml. ws. WebServiceClient;

/**
* This class was generated by the jaxws si.
* JAX-WS RI 2.0 _ 02-b08-fcs
* Generated source version: 2.0
*
*/
@ Webserviceclient (name = "geoglobeserver", targetnamespace = "http://www.geostar.com.cn", wsdllocation = "http: // 126.33.8.183: 9999/geoglobeserver? WSDL ")
Public class geoglobeserver
Extends Service
{

Private Final Static URL geoglobeserver_wsdl_location;

Static {
URL url = NULL;
Try {
Url = new URL ("http: // 126.33.8.183: 9999/geoglobeserver? WSDL ");
} Catch (malformedurlexception e ){
E. printstacktrace ();
}
GEOGLOBESERVER_WSDL_LOCATION = url;
}

Public GeoGlobeServer (URL wsdlLocation, QName serviceName ){
Super (wsdlLocation, serviceName );
}

Public GeoGlobeServer (){
Super (GEOGLOBESERVER_WSDL_LOCATION, new QName ("http://www.geostar.com.cn", "GeoGlobeServer "));
}

/**
*
* @ Return
* Returns WSDemo
*/
@ WebEndpoint (name = "WSDemoPort ")
Public WSDemo getWSDemoPort (){
Return (WSDemo) super. getPort (new QName ("http://www.geostar.com.cn", "WSDemoPort"), WSDemo. class );
}

}

// WSDemo. java

Import javax. jws. WebMethod;
Import javax. jws. WebParam;
Import javax. jws. WebResult;
Import javax. jws. WebService;
Import javax. jws. soap. SOAPBinding;

/**
* This class was generated by the jaxws si.
* JAX-WS RI 2.0 _ 02-b08-fcs
* Generated source version: 2.0
*
*/
@ WebService (name = "WSDemo", targetNamespace = "http://www.geostar.com.cn ")
@ SOAPBinding (parameterStyle = SOAPBinding. ParameterStyle. BARE)
Public interface WSDemo {

/**
*
* @ Param input
* @ Return
* Returns java. lang. String
*/
@ WebMethod
@ WebResult (name = "doSomethingResponse", targetNamespace = "http://www.geostar.com.cn", partName = "doSomethingResponse ")
Public String doSomething (
@ WebParam (name = "input", targetNamespace = "http://www.geostar.com.cn", partName = "input ")
String input );

}
// ObjectFactory. java

Import javax. xml. bind. JAXBElement;
Import javax. xml. bind. annotation. XmlElementDecl;
Import javax. xml. Bind. annotation. xmlregistry;
Import javax. xml. namespace. QNAME;

/**
* This object contains factory methods for each
* Java content interface and Java element Interface
* Generated in the clienttc package.
* <P> An objectfactory allows you to programatically
* Construct new instances of the Java Representation
* For XML content. The Java representation of XML
* Content can consist of Schema derived Interfaces
* And classes representing the binding of Schema
* Type Definitions, element declarations and Model
* Groups. factory methods for each of these are
* Provided in this class.
*
*/
@ Xmlregistry
Public class ObjectFactory {

Private final static QName _ DoSomethingResponse_QNAME = new QName ("http://www.geostar.com.cn", "doSomethingResponse ");
Private final static QName _ Input_QNAME = new QName ("http://www.geostar.com.cn", "input ");

/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: ClientTC
*
*/
Public ObjectFactory (){
}

/**
* Create an instance of {@ link JAXBElement }{@ code <}{@ link String }{@ code> }}
*
*/
@ XmlElementDecl (namespace = "http://www.geostar.com.cn", name = "doSomethingResponse ")
Public JAXBElement <String> createDoSomethingResponse (String value ){
Return new JAXBElement <String> (_ DoSomethingResponse_QNAME, String. class, null, value );
}

/**
* Create an instance of {@ link JAXBElement }{@ code <}{@ link String }{@ code> }}
*
*/
@ XmlElementDecl (namespace = "http://www.geostar.com.cn", name = "input ")
Public JAXBElement <String> createInput (String value ){
Return new jaxbelement <string> (_ input_qname, String. Class, null, value );
}

}

We can write a test class: wsdemoclient. Java

The Code is as follows:

Public class wsdemoclient {

/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo auto-generated method stub
Geoglobeserver Server = new geoglobeserver ();
Wsdemo demo = server. getwsdemoport ();
System. Out. println (Demo. dosomething ("zhuhua "));

}

}

Click Run To Run wsdemoclient. Java

On the console, we can see:

Hello: Hua

Related Article

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.