SOA (Development of Web service in Tuscany)

Source: Internet
Author: User
Tags sca

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

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.