WebService (a) Simple WebService instance __web

Source: Internet
Author: User
Tags soap wsdl

WebService Basic Knowledge

Interaction between heterogeneous platforms


Java implementations:
JAX-ws
Framework:
Cxf
AXIS
METRO

Jax method generates a new interface and implements the interface class (for storing on the client side)
-d specifies the generated directory
-KEEP Specifies whether to generate a source file
-P designated Registration
-verbose Show Build Detail process
java:wsimport-d D:\sid\workspace_webservice\wsimport-keep-verbose http://localhost:6666/ns?wsdl


SEI (Service EndPoint Interface)
SIB (Service implement Bean)


WSDL Base:

Soap:simple Object Access Protocol (protocol)
SoapMessage:

WSDL: (appears after the URL)
Types: The type used to define access
Message:soap
PortType: Indicates the interface name (binding in and Out;operation: specifying the method Name)
Binding: Specifies the format (style:document and RPC) used to deliver the message
Service: Specifies the basic information published by the service

Java EE view:
You can view the Web service Explorer
You can see the sending and returning XML of the SOAP protocol

You can use Tcpmon to capture clearer xml
You can set your own listening port and then use Tcpmon to forward it.


Instance:

Package org.sid.service;

Import Javax.jws.WebParam;
Import Javax.jws.WebResult;
Import Javax.jws.WebService;

@WebService Public
interface Imyservice {
	@WebResult (name= "Addresult") public
	int Add (@WebParam (name= "a ") int A, @WebParam (name=" b ") int b);

	@WebResult (name= "Minusresult") public
	int minus (@WebParam (name= "a") int A, @WebParam (name= "b") int b);

	@WebResult (name= "login") Public
	User Login (@WebParam (name= "username") String username, @WebParam (name= " Password ") String password);
	
}
Package org.sid.service;

Import Javax.jws.WebParam;
Import Javax.jws.WebResult;
Import Javax.jws.WebService;

@WebService (endpointinterface= "Org.sid.service.IMyService") Public
class Myserviceimpl implements Imyservice {

	@Override Public
	int Add (int a, int b) {
		System.out.println (a+b);
		return a+b;
	}

	@Override public
	int minus (int a, int b) {
		System.out.println (a);
		return a-B;
	}

	@Override
	@WebResult (name = "Login") Public
	User Login (@WebParam (name = "username") String username
			@ Webparam (name = "password") String password) {
		User user = new user ();
		User.setusername (username);
		User.setpassword (password);
		return user;
	}

}



Package org.sid.service;

Import Javax.xml.ws.Endpoint;

public class MyServer {public
	static void Main (string[] args) {
		String address = "Http://localhost:6666/ns"; 
  
   endpoint.publish (Address, New Myserviceimpl ());
	}
}

  


Package org.sid.service;

Import java.net.MalformedURLException;
Import Java.net.URL;

Import Javax.xml.namespace.QName;
Import Javax.xml.ws.Service;

public class TestClient {public
    static void Main (string[] args) {
        try {
            //Create access WSDL server address URL url
            = new URL ("http://localhost:6666/ns?wsdl");
            NamespaceURI and Localpart find QName QName = new QName in http://localhost:6666/ns?wsdl with specific information about the QName fatal service
            ("HTTP/ service.sid.org/"," Myserviceimplservice ");
            Create Services service Service
            = service.create (URL, QName);
            Implement the interface (dependent on the interface)
            Imyservice ms = Service.getport (imyservice.class);
            Ms.add (at all);
        } catch (Malformedurlexception e) {
            e.printstacktrace ();}}
}


After Wsimport, the resulting file is tested into a new client project

Use the following client calls:

Package org.sid.service;


public class TestClient2 {public
	static void Main (string[] args) {
		Myserviceimplservice msis = new Myserviceimpls Ervice ();
		Imyservice ms = Msis.getmyserviceimplport ();
		Ms.add (2);}
}



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.