[Java] WebService's Custom release WSDD tutorial (ii) __java

Source: Internet
Author: User
Introduction:WebService is a remote invocation technology across programming languages and across operating system platforms.
Cross-programming languages and cross-operational platforms, that is, server-side programs are written in Java, client programs can be written in other programming languages, and vice versa. Cross-operating system platforms refer to server-side programs and client programs that can run on different operating systems.

A remote call is a method on a computer a program that can call an object on another computer B, for example, UnionPay provides the POS card system to the mall, and the code of the transfer method of the POS transfer call in the mall is actually running on the bank server.

Axis offers two ways to publish WebService:

1. Instant release (instantdeployment);

For more information, see: [Java] WebService Instant release JWS tutorial (i)

2. Custom Release (customdeployment);

Custom Publish way: WSDD Way

1> Instant Release is an exciting technology that makes Web services development so simple, but instant publishing isn't always the best choice, for example, some applications are provided by third parties, and we don't buy source code, There are only. class files, but we want to release some of the functionality of this application system to the Web services so that it can function more widely, and there is nothing to do with instant publishing technology at this time. In addition, the instant release technology is not flexible enough to make more service configurations, which makes it impossible to meet the needs of some specific systems.

2> the Java source code into a. class file, put it in the "%tomcat_home%/webapps/axis/" directory and start publishing. Custom publications do not need to build. jws files, but you must create a service publishing profile DEPLOY.WSDD in the "%tomcat_home%/webapps/axis/web-inf/" directory (WEB Service deployment Descriptor), this file is responsible for describing the name of the service, the entrance and other information! Development Preparation:

Axis Services Download:http://apache.fayea.com/axis/axis/java/1.4/

1. axis-src-1_4.zip download is finished, decompression compressed package;

2. Go to axis-src-1_4\axis-1_4\webapps directory, copy axis entire folder;

3. Paste into the tomcat\webapps directory, such as Tomcat\webapps\axis;

4. Start Tomcat, the address bar input http://localhost:8080/axis carriage return, if the presence of Apache-axis and other content on the certification service deployment success;

5. Start into case writing, create a Java Project in ECLIPSE\MYECLIPSTC, create package (EG:COM.WEBSERVICE.WSDD), then write a Hellowsdd.java, and finally compile this class;

The 5.1 directory structure is as follows:

5.2 Java Classes written:

/**
 * @ Features: Web Service Custom published Class  --> method
 * @author: Bu regret
 * @q q:379839355 *
 @ June 2, 2015 11:54:47
 * /
package COM.WEBSERVICE.WSDD;

public class HELLOWSDD {
	private int count = 0;
	public string Hello (string name) {
		count++;
		System.out.println ("Hello call times:" + count);
		Return "Welcome:" + Name;
	
	public float sum (float A, float b) {
		count++;
		SYSTEM.OUT.PRINTLN ("Sum call times:" + count);
		return a + B;
	}
}
/**
 * @ function: Compile hellowsdd
 * @author: Bu regret
 * @q q:379839355
 * @ June 3, 2015 a.m. 12:03:09/package
com.we BSERVICE.WSDD;

public class JAVACHELLOWSDD {public
	static void Main (string[] args) {
		new HELLOWSDD ();
	}
}
6. Find the project path after compiling and find the compiled Hellowsdd.classFile, then back to the COM directory, copy the COM folder, and paste it into the tomcat\webapps\axis\web-inf\classes, as shown in the picture;

7. Next we need to customize our WSDD XML file, which is named DEPLOY.WSDD and created in the Web-inf directory of the current Web project;

<span style= "FONT-SIZE:12PX;" ><?xml version= "1.0" encoding= "UTF-8"?> <deployment name=
"test" xmlns= "http://xml.apache.org/axis/ wsdd/" 
    xmlns:java=" Http://xml.apache.org/axis/wsdd/providers/java >
  <!--provider= "Java:rpc" is a service type , in addition to RPC, there are document, wrapped, and message modes-->  
  <service name= "HELLOWSDD" provider= "Java:rpc" >
	<! --tells the service should call the class-->  
    <parameter name= "ClassName" value= "Com.webservice.wsdd.HelloWSDD"/>
	<!--* Represents all methods that expose-->
    <parameter name= "Allowedmethods" value= "*"/>
	<!--The scope of the current WebService, respectively: request, Session, Application-->
	<parameter name= "Scope" value= "Application"/>
  </service>
</deployment>
</span>

8. After the configuration is completed, you need to use the Adminclient tool class provided by axis to help us release the WebService until SERVER-CONFIG.WSDD is generated,
The steps are as follows:
8.1 into the tomcat\webapps\axis\web-inf\ directory
8.2 Hold down the SHIFT key in the current directory
8.3 Then right click here to open Command window
8.4 The DOS window appears and the path is d:\tomcat6\webapps\axis\web-inf>
8.5 input compiler command: Java-djava.ext.dirs=lib org.apache.axis.client.AdminClient DEPLOY.WSDD
8.6 If the report connection failed, start Tomcat recompile once

      Exception:axisfault
         faultcode: {http://schemas.xmlsoap.org/soap/envelope/}server.userexception
         Faultsubcode:
         faultString:java.net.ConnectException:Connection refused:connect
         faultactor:
         Faultnode:
         faultdetail: {http://xml.apache.org/axis/}stacktrace:java.net.connectexception:conne
        ction Refused:connect
8.7 compilation succeeded, the current directory d:\tomcat6\webapps\axis\web-inf> generate SERVER-CONFIG.WSDD configuration file.

9. Visit the http://localhost:8080/axis/and enter the list directory to see if a custom service method appears;

10. Write a method class Clientwsdd.javathat accesses the Web service and invokes its services;

/** * @ Features: Web Service wsdd * @author: Bu regret * @q q:379839355 * @ June 3, 2015 Morning 1:23:26 package * * com.client;
Import Javax.xml.namespace.QName;
Import Org.apache.axis.client.Call;
Import Org.apache.axis.client.Service; /** * Introduction: * WebService is a cross programming language and across the operating system platform remote invocation technology.
 <br/> *    The so-called cross-programming language and cross operating platform, that is, server-side programs in Java writing, client programs can be written in other programming languages, and vice versa. * Cross-operating system platforms refer to server-side programs and client programs that can run on different operating systems. <br/> *    called remote Invocation is a method on a computer a program that can call an object on another computer B, for example, UnionPay provides a POS card system for shopping malls, The store's POS machine transfer call to the transfer method code is actually running on the bank server. <br/> @ Step:<br/> * 2. Custom release *    1> write Java Custom Service code, HELLOWSDD.CLASS with engineering structure directory, and placed to Tomcat\webapps\axi s\web-inf\ Directory;<br/> *    2> need to customize our WSDD XML file, which is named DEPLOY.WSDD, created in the Web-inf directory of the current WEB project;<br/> *    3> After the configuration, we need to use the Adminclient tool class provided by axis to help us release the WebService until Server-config.wsdd;<br/> *     4> writes the client and invokes the remote interface in the Web service and its methods;<br/>/public class CLIENTWSDD {public static void main (string[) AR GS) {Try {//definition string that describes the server address to be accessed [change to the Web Service service path you want to access] string url = "Http://192.168.8.111:8080/axis/services/HelloWSDD"
			;
			Create a service services SV for a WEB service (): The new Service ();
			Creates an invocation call called = (calls) Sv.createcall ();
			Specify the source call.settargetendpointaddress (URL) of the service;
			Indicates the specific method name of the call Call.setoperationname (new QName (URL, "Hello"));
			Execute Remote Call String result = (string) call.invoke (New object[]{"Bu _ Regret"});
			SYSTEM.OUT.PRINTLN (result);
			Indicates the specific method name of the call Call.setoperationname (new QName (URL, "sum"));
			Execute Remote Call float Resultsum = (float) call.invoke (new object[]{new float (1.2), new float (1.3)});
		System.out.println ("a + b =" + resultsum);
		catch (Exception e) {e.printstacktrace (); }
	}
}
11. Execute the test, the console prints out the method's output statement, the WebService access call succeeds.


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.