JDK6 new features 10: Web Services Metadata (Web Services metadata)

  JDK6 new features 10: Web Services Metadata (Web Services metadata) 

  . Net Web Services Metadata in the morning. Net Framework 1.0, Microsoft will use metadata function (. Attribute of the net) to be exposed as tagging Web Service methods Below is demonstrated by the use of C #. Net of yuan data capabilities expose Web Service methods of code snippet. 
  (Public class TestWS 
[WebMethod]
  Public String sayHi () ( 
  Return "Hi!"; 
  ) 
  Public int add (int d1, int d2) ( 
  Return d1 + d2; 
  ) 
  ) 
  Above [WebMethod] is added to the above method sayHi metadata to tell the Web Services engine (normally ASP.NET Runtime), I need this method exposed as a Web Service, you need to help me generate the corresponding WSDL description and relevant supporting documents. add another method did not increase this metadata, Web Services for the engine will not be used to generate WSDL and related supporting documents 

  Java's Web Services Metadata 
  Java, Web services metadata with Microsoft's basically no programme on the semantic distinction, since JDK5 add metadata function (Annotation), SUN remodeling almost the entire J2EE system, as great changes, simply name Reconstruction for Java EE, Java EE (current version 5.0) will be incorporated into many metadata standards, and these include the relevant norms of Web Services, by adding metadata after the Web Services server-side programming model will follow see above fragment C # almost, and this is clearly than before the JAX-RPC programming model is simple (of course, the Axis is also very simple programming model). here to talk about the Web services metadata (JSR 181) is Java Web services in a standardized, with the Common Annotations, JAXB2, StAX, and JAX-WS SAAJ such as a common Java EE 5 Web Services technology stack. 

  JSR-181 metadata on the list below JSR-181 metadata inside all relevant parameters and uses 
  Annotation Retention Target Description 
  WebService Runtime Type 
  Tagging should be exposed to the type or Web Services Interface 
  WebParam Runtime Parameter customized service approach to the parameters of the mapping WSDL 
  WebResult Runtime Method customized service approach to the return value of the mapping WSDL 
  WebMethod Runtime Method customize individual service approach to the mapping WSDL 
  Oneway Runtime Method @ WebMethod连用must be that the importation was not only marked the output method, which requires the tagging method can not be a return value, we can not checked exception statement 

  HandlerChain Runtime Type and Method, Field will be Web services with external Handler chain linking 
  SOAPBinding Runtime Type and Method custom SOAPBinding 

  JSR-181 examples of the use of metadata 

  Package WebServices; 

  Import java.io.File; 
  Import java.io.IOException; 
  Import javax.jws.Oneway; 
  Import javax.jws.WebMethod; 
  Import javax.jws.WebParam; 
  Import javax.jws.WebResult; 
  Import javax.jws.WebService; 
  Import javax.xml.ws.Endpoint; 

  / ** 
  * @ Author chinajash 
  * / 
  @ WebService (targetNamespace = "http://blog.csdn.net/chinajash" serviceName = "HelloService") 
  (Public class WSProvider 
  @ WebResult (name = "Greetings") / / customize the method return value in the description of the relevant WSDL 
  @ WebMethod 
  Public String sayHi (@ WebParam (name = "MyName") String name) ( 
  Return "Hi," + name; / / @ WebParam parameter is the definition of the relevant name in the WSDL description 
  ) 
  @ Oneway / / show that the service is one-way, did not return value, and should not be unusual statement inspection 
  @ WebMethod (action = "printSystemTime" operationName = "printSystemTime") / / WSDL definition of the method described in the relevant 
  Public void printTime () ( 
  System.out.println (System.currentTimeMillis ()); 
  ) 
  Public static void main (String [] args) ( 
  Thread wsPublisher = new Thread (new WSPublisher ()); 
  WsPublisher.start (); 
  ) 
  Private static class WSPublisher implements Runnable ( 
  Public void run () ( 
  / / Published WSProvider http://localhost:8888/chinajash/WSProvider to this address, must be called before the order wsgen 
  / / Generate the support services category WSProvider category, orders are as follows: 
  / / Wsgen-cp. WebServices.WSProvider 
  Endpoint.publish ( "http://localhost:8888/chinajash/WSProvider" new WSProvider ()); 
  ) 
  ) 
  ) 

  If you want to see Web Services Engine generated WSDL document compliance with the above meta-data, we do not have the necessary will be deployed to the above WSProvider JSR-181 support the application server or Servlet forms of Web Services Engine, JDK6 has already provided a very simple the mechanism can be used to test and publish Web Services, Below talk about how JDK6 environment Published Web Services and Show generated WSDL 
  1. Will <JDK_HOME> / bin join the path environment variable 
  2. Switch on the command line under the current directory to the class documents WSProvider the directory, run the following command 
  Wsgen-cp. WebServices.WSProvider 
  In this example generates the following three categories of documents and source code files class 
SayHi
SayHiResponse
PrintTime
  3. Implementation of the following code to release WSProvider http://localhost:8888/chinajash/WSProvider, where can perform WSProvider category on the main methods can be 
  Endpoint.publish ( "http://localhost:8888/chinajash/WSProvider" new WSProvider ()); 
  4. Browser can be seen on the importation of http://localhost:8888/chinajash/WSProvider?wsdl generated WSDL documents, in order to save space, here is not to affix generated WSDL document, we can try their own hands. 





  Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1485082 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply