First, related concepts
1. SOA (Service Oriented architecture) services-oriented architecture.
2. SCA (service component architecture, services architecture) provides a programming model to support SOA-based application implementations.
3, Tuscany is an open source framework based on SCA.
4, AXIS2 is the Apache Exit Support Web Service model of the tool software, Tuscany Java SCA is actually using AXIS2 to publish the component externally as a Web service.
Second, the development process
1. Design Ideas
2, to achieve the service end of the specific services
Myserviceinterface.java
Public Interface myserviceinterface{ public String function ();
Myserviceimp.java
3. Write the server configuration file
Myservice.composite
<?XML version= "1.0" encoding= "UTF-8"?><Compositexmlns= "http://www.osoa.org/xmlns/sca/1.0"targetnamespace= "Http://myService"name= "MyService">
<!--service tag for configuring SCA Services--<Servicename= "Hello"Promote= "Myservicecomponent"> <!--The Name property indicates the service, promote indicates which component the service is going to promote -- <binding.wsURI= "Http://127.0.0.1:8084/myService"/> <!--<bindling.ws> tags are used to bind a service as a Web service. URI gives the bound Web service access URI-- </Service>
<!--configuration Components--<Componentname= "Myservicecomponent"> <Implementation.javaclass= "com. Myserviceimp "/> </Component> </Composite>
4. Start the service-side program
Startwebservice.java
Importjava.io.IOException;ImportOrg.apache.tuscany.sca.host.embedded.SCADomain; Public classStartwebservice { Public Static voidMain (string[] args) {Scadomain Scadomain= Scadomain.newinstance ("Com/myservice.composite");//Load composition component filesTry{System.out.println ("SOA service started ..."); System.in.read (); } Catch(IOException e) {e.printstacktrace (); } scadomain.close (); }}
5. Writing Client Programs
//Required PackagesImportJavax.xml.namespace.QName;ImportOrg.apache.axis2.AxisFault;Importorg.apache.axis2.addressing.EndpointReference;Importorg.apache.axis2.client.Options;Importorg.apache.axis2.rpc.client.RPCServiceClient; Public classmyrpcclient{ Public Static voidMain (string[] args)throwsaxisfault{rpcserviceclient serviceclient=Newrpcserviceclient (); Options Options=serviceclient.getoptions ();
String uri = Webserviceinfoutil.geturl ("Http://127.0.0.1:8084/myService"),//uri and targetnamespace and server-side configuration are consistent
String targetnamespace = Webserviceinfoutil.getnamespace ("http://myService");
//set the address of the service providerEndpointReference Targetepr =Newendpointreference (URI); Options.setto (TARGETEPR); //to set the operation of the service to invokeQName Opgetsearchkeyword =NewQName (targetnamespace, "function"); //return typeclass[] Returntypes =NewClass[] {string[].class}; //sets the parameter value of the called method (the parameter value required by the service-side program)object[] Opgetsearchinfoserviceargs =NewOBJECT[]{ARGS1}; //Gets the result of the call, assuming that the method being called returns a string[] type//two different methods//Method 1,string[] Response =(string[]) serviceclient.invokeblocking (Opgetsearchkeyword, Opgetsearchinfoserviceargs, returnTypes )[0]; //Method 2,object[] Response =(string[]) serviceclient.invokeblocking (Opgetsearchkeyword, Opgetsearchinfoserviceargs, returnTypes ); String[] Result= (string[]) response[0]; ......//operate on the resulting results }}
Reference: SOA Practitioners: System integration in distributed environments Deng