首页 > 代码库 > Visual Studio/Eclipse调用 JBoss5中的WebService

Visual Studio/Eclipse调用 JBoss5中的WebService

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 "你好,JBoss5 WebService 欢迎你:[" + 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添加WebService引用后, 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 = 22;            var rspAdd = client.add(reqAdd);            var ret = rspAdd.result;            Console.WriteLine(ret);            //for (int i = 0; i < 10; i++)            //{                JBossHelloServiceRef.sayHello reqSay = new JBossHelloServiceRef.sayHello();                reqSay.name = "张三";                var rspSay = client.sayHello(reqSay);                Console.WriteLine(rspSay.result);            //}            Console.ReadKey();        }    }}

 Java端调用方法:

1. 在${jboss_home}/bin目录,在cmd中执行: 

D:\DevPrograms\jboss\jboss-5.1.0.GA\bin>wsconsume.bat -k http://localhost:8080/HelloWorldJBoss5/hello?wsdl

生成代理文件.

2. 复制到java项目中

3. 添加测试代码

public class TestMain {	/**	 * @param args	 */	public static void main(String[] args) {		HelloWebServiceService svcProxy = new HelloWebServiceService();		HelloWebService svc = svcProxy.getHelloWebServicePort();		int c = svc.add(11, 22);		System.out.println(c);				String ret = svc.sayHello("吴xx11");		System.out.println(ret);	}}

  

 

Visual Studio/Eclipse调用 JBoss5中的WebService