〖JAVE经验〗Java认证考试:WebService架构和应用四

Integer ret = (Integer)call.invoke(new Object[]{ 1,3 } );

System.out.println(ret);

} catch (Exception e){

System.err.println(e.toString());

}

}

《2》动态代理方式(Dynamic Proxy)

动态代理需要一个本地的接口作为代理

Java代码

public interface ITestDynameicProxy extends Remote {

public String getMessage()throws RemoteException;

}

public static void main(String[]args)throws Exception {

String wsdlUrl = “http://localhost:8080/axis/test/Test.jws?wsdl”;

String nameSpaceUri = “http://soapinterop.org/”;

String serviceName = “Test1Service”;

String portName = “Test1”;

ServiceFacTory serviceFacTory = ServiceFacTory.newInstance();

Service service = serviceFacTory.createService(

new URL(wsdlUrl),new QName(nameSpaceUri,serviceName));

ITestDynameicProxy proxy = (ITestDynameicProxy)service.getPort(

new QName(nameSpaceUri,portName),ITestDynameicProxy.class);

System.out.println(proxy.getMessage());

}

通过输入wsdl地址,命名空间地址和服务名,用服务工厂创建出一个服务实例,再通过设置端口名得到一个服务类型的服务代理对象,通过该代理,就可以直接访问web服务了。

《3》静态方式(Stubs)

①按常规方式发布一个WebService

②得到wsdl文件

* 通过web页面直接另存为

* 通过Java2WSDL工具类生成

(java org.apache.axis.wsdl.Java2WSDL -o demo1.wsdl -l http://localhost:8080/axis/services/demo -n http://www.itcast.cn/test.Demo)

③利用WSDL2Java工具类生成客户端调用代码

(java org.apache.axis.wsdl.WSDL2Java demo.wsdl -p client)

④在生成的代码基础上,进行客户端的调用

Java代码

public static void main(String[]args)throws ServiceException,RemoteException {

DemoServiceLocaTor demoService = new DemoServiceLocaTor();

Demo demo = demoService.getdemo();

System.out.println(demo.getMessage());

}

更多免费相关学习经验请访问:Tore_m_1206686_21115_1_1.html”>http://www.shangxueba.com/sTore_m_1206686_21115_1_1.html

没有什么可留恋,只有抑制不住的梦想,没有什么可凭仗,

〖JAVE经验〗Java认证考试:WebService架构和应用四

相关文章:

你感兴趣的文章:

标签云: