This is an example of using Java to call the C # version of the WebService interface:
C # Interface:
<span style= "FONT-SIZE:11PX;" >using system;using system.web;using system.web.services;using system.web.services.protocols;using System.Web.Services.Description; [WebService (Namespace = "http://www.tangs.com/")] [WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]public class service:system.web.services.webservice{ Public Service () ... {//If you are using a design component, uncomment the following line//initializecomponent ();} [SoapRpcMethod (Action = "Http://www.tangs.com/Add", Requestnamespace = "Http://www.tangs.com/T", Responsenamespace = " Http://www.tangs.com/T ", use = soapbindinguse.literal)] [webmethod]public int Add (int a, int b) ... {return a + B;} [SoapRpcMethod (Action = "Http://www.tangs.com/Hello", Requestnamespace = "Http://www.tangs.com/T", Responsenamespace = "Http://www.tangs.com/T", use = soapbindinguse.literal)] [webmethod]public String HelloWorld () ... {return "Hello, world!";}} ...</span>
Java's call to add methods and HelloWorld methods in this Web service:
1, Parameter method: Add
<span style= "font-size:11px;" >public static void Addtest () {Try ... {Integer i = 1; Integer j = 2;//webservice URL String service_url = "Http://localhost:4079/ws/Service.asmx"; Service service = new service (); Call Call Service.createcall (); Call.settargetendpointaddress (New Java.net.URL (Service_url));//sets the method call.setoperationname to be called (The New QName ("http:// Www.tangs.com/T "," ADD ");//The method requires a parameter Call.addparameter (" A ", Org.apache.axis.encoding.XMLType.XSD_INT, Javax.xml.rpc.ParameterMode.IN); Call.addparameter ("B", Org.apache.axis.encoding.XMLType.XSD_INT, Javax.xml.rpc.ParameterMode.IN);// The return value type of the method Call.setreturntype (Org.apache.axis.encoding.XMLType.XSD_INT); Call.setusesoapaction (TRUE); Call.setsoapactionuri ("Http://www.tangs.com/Add");//Call the method Integer res = (integer) call.invoke (new object[] ... {i, J}); System.out.println ("Result:" + res.tostring ());} catch (Exception e) ... {System.err.println (e);} }...</span>
Run, result returned: Result: 3
2. Non-parametric method: HelloWorld
<span style= "FONT-SIZE:11PX;" >public static void Hellotest () {Try ... {String endpoint = "Http://localhost:4079/ws/Service.asmx"; Service service = new service (); Call Call Service.createcall (); Call.settargetendpointaddress (new Java.net.URL (endpoint)); Call.setoperationname (New QName ("Http://www.tangs.com/T", "HelloWorld")); Call.setusesoapaction (TRUE); Call.setsoapactionuri ("Http://www.tangs.com/Hello"); string res = (string) call.invoke (new object[] ... {null}); System.out.println ("Result:" + res);} catch (Exception e) ... {System.err.println (e.tostring ());} }...</span>
As you can see, calling a Web service with no parameters is basically the same as having a parameter, but without a call, you do not need to call the Addparameter method and the Setreturntype method
Execute Query Query Results Report view: Hello, world!
Attachments in jar packages that are dependent on the Web service