WebService server and client call Method

Source: Internet
Author: User

Technology and rules
When building and using web services, we mainly use the following key technologies and rules: 1.xml: a standard method for describing data. 2. soap: indicates the Information Exchange Protocol. 3. WSDL: Web Service Description Language. 4. UDDI (Universal Description, discovery and integration): Universal Description, discovery, and integration. It is a platform-independent, XML-based protocol used to describe commerce on the Internet.
Related
In fact, the main goal of WebService is cross-platform interoperability. To achieve this goal, WebService is fully based on XML (Extensible Markup Language), XSD (XMLSCHEMA), and other standards independent of the platform and software vendors, is a new platform for creating interoperable and distributed applications. From this we can see that in the following three cases, using WebService will bring great benefits.

Use axis to write WebService:
I. Server Side
1. Required jar
Copy the JAR file of axis to the WEB-INF/lib folder. These files include:
Activation. Jar
Axis. Jar
Axis-ant.jar
Axis-schema.jar
Commons-discovery-0.2.jar
Commons-logging-1.0.4.jar
Jaxrpc. Jar
Log4j-1.2.8.jar
Mailapi. Jar
SAAJ. Jar
Wsdl4j-1.5.1.jar
Xmlsec-1.3.0.jar

2. Compile the methods in the class to be called:
Package com. id5.webservice;
Public class javabeanws {
Public String getjavabeanws (string name ){
Return "Hi ----" + name + "---- This an axis Java Bean Web Services ";
}
}

3. Compile the Web. xml file and configure axis in the file:
<Servlet>
<Servlet-Name> axisservlet </servlet-Name>
<Servlet-class>
Org. Apache. axis. Transport. http. axisservlet
</Servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> axisservlet </servlet-Name>
<URL-pattern>/services/* </url-pattern>
</Servlet-mapping>

4. Create a configuration file server-config.wsdd for publishing WebService:

<Deployment xmlns = "http://xml.apache.org/axis/wsdd"
Xmlns: Java = "http://xml.apache.org/axis/wsdd/providers/java">

<! -- Processor -->
<Handler name = "urlmapper"
Type = "Java: org. Apache. axis. Handlers. http. urlmapper"/>
<! -- A service -->
<! -- Provider = "Java: RPC" WebService is provided in the form of JavaBean -->
<Service name = "getjavabeanwebservice" provider = "Java: RPC">
<! -- Specify the Class Name of the class where the method called when WebService is called -->
<Parameter name = "classname"
Value = "com. id5.webservice. javabeanws"/>
<! -- Methods allowed for access in the class -->
<Parameter name = "allowedmethod" value = "getjavabeanws"> </parameter>
</Service>
<! -- Specify the processor -->
<Transport name = "HTTP">
<Requestflow>
<! -- Reference the preceding -->
<Handler type = "urlmapper"/>
</Requestflow>
</Transport>
</Deployment>

5. Deploy the service on the server and call: http: // localhost: 8080/mywebservice/services/getjavabeanwebservice? WSDL

Ii. Client:
Public class testcall {
Private Static final string webservice_test = "http: // localhost: 8080/mywebservice/services/getjavabeanwebservice? WSDL ";

Public static void main (string [] ARGs) throws malformedurlexception {
Testcall = new testcall ();
Testcall. callsayhello ();
}

Public void callsayhello () throws malformedurlexception {
Service = new service ();
Try {
Call call = (CALL) service. createcall ();
// Set the address
Call. settargetendpointaddress (New java.net. URL (webservice_test ));
// Set the method to be executed
Call. setoperationname (New QNAME ("http://webservice.sinosoft.com /",
"Getjavabeanws "));
// Set the parameter to be passed in. If there is no parameter to be passed in, do not enter this
Call. addparameter ("name", org. Apache. axis. constants. xsd_string,
Javax. xml. rpc. parametermode. In );
// Set the returned type
Call. setreturntype (Org. Apache. axis. constants. xsd_string );
Try {
String name = "gongpeibao ";
// Execute and call WebService
String ret = (string) Call. Invoke (new object [] {name });
System. Out. println ("ret =" + RET );
} Catch (RemoteException e ){
System. Out. println ("eeee" + E );
E. printstacktrace ();
}

} Catch (serviceexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
}

 

 

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.