Release WebService 1.1

Source: Internet
Author: User
Tags soap wsdl

webservice1.1 is a JDK-based release

1  Packagecn.itcast.service01;2 3 ImportJavax.jws.WebService;4 ImportJavax.xml.ws.Endpoint;5 6 @WebService7  Public classHelloService {8     9      Publicstring SayHello (string name)Ten     { OneSystem.out.println ("Say hello called"); A         return"Hello" +name; -      } -     //The Main method cannot be published, and the published method cannot be static the      Public Static voidMain (string[] args) -     { -         //start a new thread address content -Endpoint.publish ("Http://192.168.151.42:5678/hello",NewHelloService ()); +System.out.println ("Herer"); -     } +}

Test:

First, the user accesses http://192.168.151.42:5678/hello?wsdl and then

CMD under input wsimport-s. http://192.168.151.42:5678/hello?wsdl

Then put the code down and get rid of the *.class.

Copy Code to project test

Using bottom-up mode in HTTP://192.168.151.42:5678/HELLO?WSDL

1  PackageCn.itcast.testService;2 3 ImportCn.itcast.service01.HelloService;4 ImportCn.itcast.service01.HelloServiceService;5 6  Public classApptest {7 8      Public Static voidMain (string[] args)9     {Ten         /** One * WSDL Address service name= "Helloserviceservice" A          */ -Helloserviceservice service=NewHelloserviceservice (); -  theHelloService soap=Service.gethelloserviceport (); -String Str=soap.sayhello ("This is SSS"); - System.out.println (str); -     } +}

This enables webservice on the client Access server

There is also a client-side approach to implement the access server, this method is actually the same as the first essence, the first method takes the form of an inherited interface, the client copies multiple files.

The second method is that the client simply copies the interface, because the constructor for inheriting this interface is protected, so you can use the second method, the proxy object

Two uses the generated interface and the Service class provided by the JDK to implement access

Server-Side Add method

1      Public String SayHello2 (string name,int  N)2    {3         System.out.println (" Say hello called       --------------------"+N); 4         return "Hello" +name; 5     }

Then wsimport-s-P Cn.itcast.hello http://192.168.151.42:5678/hello?wsdl

Then simply copy the generated interface HelloService

Then the following code

1  PackageCn.itcast.testService;2 3 Importjava.net.MalformedURLException;4 ImportJava.net.URL;5 6 ImportJavax.xml.namespace.QName;7 ImportJavax.xml.ws.Service;8 9 ImportCn.itcast.hello.HelloService;Ten  One  A  Public classAppTest2 { -  -      Public Static voidMain (string[] args)throwsmalformedurlexception the{//namespace Service -Service s = service.create (NewURL ("http://192.168.151.42:5678/hello?wsdl"),NewQName ("http://service01.itcast.cn/", "Helloserviceservice")); -                                         //port for namespace service bindings -HelloService HS = S.getport (NewQName ("http://service01.itcast.cn/", "Helloserviceport"), HelloService.class); +                              -String str = Hs.sayhello2 ("Lisi", 10); + System.out.println (str); A System.out.println (Hs.getclass (). Getsimplename ()); at     } -}

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.