Java 6 was released. One of the new features that attracted me was the native support for WebServices. I would like to share my learning experience with you here.
The following describes the simplest WebServices: Package org. hermit. Study. JDK;
Import javax. JWS. webmethod;
Import javax. JWS. WebService;
Import javax. JWS. Soap. soapbinding;
@ WebService (targetnamespace = "http://jdk.study.hermit.org/client ")
@ Soapbinding (style = soapbinding. style. RPC)
Public class Hello {
@ Webmethod
Public String sayhello (string name ){
Return "Hello:" + name;
}
}
How can it be concise? Many of my friends still need to execute "wsgen-CP. <path>" in the command line"
Services written in this way can save the above steps.
Targetnamespace = "http://jdk.study.hermit.org/client" specifies the class path that the client stores after obtaining the server service. Note that http: // jdk.study.hermit.org/clientwill be placed under org.hermit.study.jdk.client.
The following is the release service: Package org. hermit. Study. JDK;
Import javax. xml. ws. endpoint;
Public class startservice ...{
Public static void main (string [] ARGs )...{
Endpoint. Publish ("http: // localhost: 8080/helloservice", new Hello ());
}
}
It's more concise. Just a word.
Http: // localhost: 8080/helloservice refers to the published address.
Run startservice... and enter http: // localhost: 8080/helloservice in the development browser? WSDL
If you can see the following content, you can <? XML version = "1.0" encoding = "UTF-8"?>
-<Definitions xmlns = "http://schemas.xmlsoap.org/wsdl/" xmlns: TNS = "http://jdk.study.hermit.org/client" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/wsdl/soap/" targetnamespace = "http://jdk.study.hermit.org/client" name = "helloservice">
<Types/>
-<Message name = "sayhello">
<Part name = "arg0" type = "XSD: string"/>
</Message>
-<Message name = "sayhelloresponse">
<Part name = "return" type = "XSD: string"/>
</Message>
-<Porttype name = "hello">
-<Operation name = "sayhello" parameterorder = "arg0">
<Input message = "TNS: sayhello"/>
<Output Message = "TNS: sayhelloresponse"/>
</Operation>
</Porttype>
-<Binding name = "helloportbinding" type = "TNS: Hello">
<Soap: Binding style = "RPC" Transport = "http://schemas.xmlsoap.org/soap/http"/>
-<Operation name = "sayhello">
<Soap: Operation soapaction = ""/>
-<Input>
<Soap: Body use = "literal" namespace = "http://jdk.study.hermit.org/client"/>
</Input>
-<Output>
<Soap: Body use = "literal" namespace = "http://jdk.study.hermit.org/client"/>
</Output>
</Operation>
</Binding>
-<Service name = "helloservice">
-<Port name = "helloport" binding = "TNS: helloportbinding">
<Soap: address location = "http: // localhost: 8080/helloservice"/>
</Port>
</Service>
</Definitions>