Learning Java 6 (1) WebServices (1) Server

Source: Internet
Author: User
Tags wsdl
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>

 

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.