Development and WebService call this document describes how to use Java and. Net to call WebService 1. Write an application in Java, such as: (calculator. Java)
Public class calculator {public int add (int I, Int J) {return I + J;} public int substract (int I, Int J) {return I-j ;}
1. Place it under Axis and rename it calculator. jws2. use axis to generate the WSDL and copy the URL in IE. This will be used below. 3. Call Web Service 1) Call. Net to create a project (either winform or Asp.net ). On the start page, place a text input box to display the result of calling Web Services, and place a button to click to call Web Services. Then, select "add web reference" and copy the obtained WSDL address in the "WSDL" column. Enter the Web reference name "erervice" and click "add reference. In this case, we can see this web reference in solution Explore of vs.net.
Enter the following code in the button clicking event:
Int I = int. parse (textbox2.text. tostring (); Int J = int. parse (textbox3.text. tostring (); assumervice. calculatorservice JS = new assumervice. calculatorservice (); textbox1.text = Js. add (I, j ). tostring ();
The assumervice references the Web service as its own name, for example:
Calculatorservice is the name of the Service in WSDL, for example:
1) use Java to call wenservicea) first create a class (testnetservice. java) B) add all jar files in WEB-INF/lib in axis to lib reference c) Add the following code in the new class: Import Java. util. date; import Java. text. dateformat; import Java. util. date; import Java. text. dateformat; import Org. apache. axis. client. call; import Org. apache. axis. client. service; import javax. XML. namespace. QNAME; import Java. lang. integer; import javax. XML. RPC. parametermode; public class testnets Ervice {public testnetservice () {} public static void main (string [] ARGs) {try {INTEGER I = new INTEGER (1); integer J = new INTEGER (2 ); string endpoint = "http: /localhost: 8080/axis/calculator. JWS "; Service = new service (); call = (CALL) service. createcall (); call. settargetendpointaddress (New java.net. URL (endpoint); call. setoperationname (New QNAME ("http://www.my.com/SU", "add"); Cal L. addparameter ("A", org. apache. axis. encoding. xmltype. xsd_date, javax. XML. RPC. parametermode. in); call. addparameter ("B", org. apache. axis. encoding. xmltype. xsd_date, javax. XML. RPC. parametermode. in); call. setreturntype (Org. apache. axis. encoding. xmltype. xsd_int); call. setusesoapaction (true); call. setsoapactionuri ("http://www.my.com/Rpc"); integer k = (integer) Call. invoke (new object [] {I, j}); system. out. printl N ("result is" + K. tostring () + ". ");} catch (exception e) {system. err. println (E. tostring () ;}} d) Note: Here, string endpoint = "http: // localhost: 8080/axis/calculator. JWS "; the URL is the call of the local JWS file. setoperationname (New QNAME ("http://www.my.com/SU", "add"); add is the name of the function in the application, or the value of the operation name in the WSDL.
In this way, a. Net client is complete, and the test is normal. OK. The result is as follows: