"WebService" WSDL configuration in detail and using annotations to modify the WSDL configuration

Source: Internet
Author: User
Tags wsdl

WebService Series Articles:
"WebService" takes you into the WebService world.
"WebService" Custom WebService service and its invocation

Before analyzing the basic knowledge of WS, we know that WSDL is a very important document in WS, we can get the relevant information of WS by parsing the WSDL document, in fact, if you do not understand the structure of the document, the problem is not very large, as long as it will be resolved to develop. But if you want to build a WSDL that fits your project, or a more humane one, or from a readability perspective, you need to have some configuration for the WS code, such as the WS name, parameters, and so on, and you need to have some understanding of the WSDL document. This article is mainly from two angles: one is to explain the related configuration in WSDL, and the second is how to specify these configurations through annotations in the WS program.

1. Detailed WSDL configuration

To generate the WSDL, we first have to have a WS, or we use the simple WS mentioned in the previous article, as follows:

 @WebService  // The default static method is not able to send the WS service  public  class  mywebservice  { public  String sayhello  (String name) { return  name +  Hello! "; } public  static   void  main  (string[] args) {String address =  "http: "; Endpoint.publish (address, new  MyWebService ()); System.out.println ( "access to the WSDL address is:"  + address + "); }}

Run a bit, you can open the WS service, request Http:// to see the WSDL page, and then analyze the WSDL file in the corresponding relationship with the above program, see (for the sake of clarity, I will not shrink the diagram):

As we can see, the generated WS service name is a service on the back of the original class, and the type name is appended with a port after the original class, including the parameter defaults to ARG0, the return value is return, and so on, which can be seen from the WSDL file. The class names in Java code generated by this WSDL are naturally the default, and if we want to modify these default configurations, we need to set them up with annotations when we write WS.

2. Modifying the WSDL configuration with annotations

We modify the WS above and use annotations to configure the name we need, as follows

/* * Custom WS service, jdk1.6 version only supports soap1.1 format, jdk1.7 and above support soap1.2 format * Release WS service only need @webservice annotations, if you want better maintainability, you can use annotations to implement * */ @WebService //The default static mode is that the WS service cannot be published(name="MyWebService1",//The name of the service implementation classServicename="MyWebServiceService1",//The service is added by default after the name of the publisherPortname="MyWebServicePort1",Name of the service type: By default add Port after the published service implementation (MyWebService)Targetnamespace="Ws.client.test"    //Publish the WS service namespace, which defaults to the "write down" of the current service pack path, which is also the default package path for the Wsimport command to generate the Java class-P) Public  class mywebservice {    @WebMethod(exclude=true)The //default public method can be published as a WS service, and if you want to exclude it, configure Exclude=true     PublicStringSayHello(String name) {System.out.println ("Name:"+ name);returnName +"Oh, hello!"; }//You can specify the method name, parameter name, and return value in the WSDL    @WebMethod(operationname="SayHello") Public@Webresult(name="Result") String SayHello2 (@WebParam(name="Name") String name,@WebParam(name="Age")intAge) {System.out.println ("Name:"+ name);returnName +"Hello!, Age is:"+ age; } Public Static void Main(string[] args) {//One port can publish multiple WS servicesString address="Http://";//Create a service endpoint, banding the implementation class of the serviceEndpoint.publish (Address,NewMyWebService ()); System.out.println ("The address of the access WSDL is:"+ Address +"? WSDL "); }}

With these annotations, I reconfigure the WS-Service-related information, run it, and compare the annotations to see the generated WSDL:

As you can see, the configuration in the generated WSDL is exactly what we specify, so that the classes and methods in the Java code obtained by parsing the WSDL file are customized to meet the specific requirements in practice.

-Willing to share and progress together!
--My Blog home: http://blog.csdn.net/eson_15

"WebService" WSDL configuration in detail and using annotations to modify the WSDL configuration

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.