1. Hellowebservice.java
Package Com.xx.webservices;import Javax.jws.webmethod;import Javax.jws.webparam;import javax.jws.WebResult;import Javax.jws.WebService; @WebServicepublic class Hellowebservice {@WebMethod @webresult (name= "result") public String SayHello (@WebParam (name= "name") String name) {System.out.println ("SayHello:" + name); return "Hello, JBoss5 WebService welcome you: ["+ name +"] ";} @WebMethod @webresult (name= "result") public int Add (@WebParam (name= "a") int A, @WebParam (name= "b") int b) {return a + B;}}
2. Web. xml
<servlet><servlet-name>Hello</servlet-name><servlet-class> com.xx.webservices.hellowebservice</servlet-class></servlet><servlet-mapping>< Servlet-name>hello</servlet-name><url-pattern>/hello</url-pattern></servlet-mapping >
3. Vs Add WebService Reference, Progam.cs
Using system;using system.collections.generic;using system.linq;using system.text;namespace HelloJBossService{ Class program { static void Main (string[] args) { jbosshelloserviceref.hellowebserviceclient client = new Jbosshelloserviceref.hellowebserviceclient (); Jbosshelloserviceref.add Reqadd = new Jbosshelloserviceref.add (); REQADD.A = -11; REQADD.B =; var rspadd = Client.add (reqadd); var ret = Rspadd.result; Console.WriteLine (ret); for (int i = 0; i < i++) //{ Jbosshelloserviceref.sayhello reqsay = new Jbosshelloserviceref.sayhello () ; Reqsay.name = "Zhang San"; var Rspsay = Client.sayhello (Reqsay); Console.WriteLine (Rspsay.result); } Console.readkey ();}} }
Java Side Call Method:
1. In the ${jboss_home}/bin directory, execute in cmd:
d:\devprograms\jboss\jboss-5.1.0.ga\bin>wsconsume.bat-k http://localhost:8080/HelloWorldJBoss5/hello?wsdl
Generate proxy files.
2. Copying to a Java project
3. Add test Code
public class Testmain {/** * @param args */public static void main (string[] args) {Hellowebserviceservice svcproxy = new H Ellowebserviceservice (); Hellowebservice svc = Svcproxy.gethellowebserviceport (); int c = Svc.add (11, 22); System.out.println (c); String ret = Svc.sayhello ("Wu xx11"); SYSTEM.OUT.PRINTLN (ret);}}
Visual Studio/eclipse calls the webservice in JBOSS5