正 文

通过动态解耦来简化Web服务调用


www.7dspace.com  更新日期:2005-10-15 4:53:01  七度空间


  清单 3. 远程服务

public class RemoteServiceImpl implements IService
{
/* get the service outputs */
/* outputs are from the web service running in the location */
/* mentioned in the serviceURI */

public ….. getFunction()
{
adapter.examples.Function service = null;
String serviceURI = "http://……../Function/";
String wsdlURI = "http://localhost:8080/Function/";
Try
{
// init the lookup
WebServiceLookup lookup = (WebServiceLookup)
……….
// get the instance of the Web services interface
// from the lookup
service = (adapter.examples.Function)
lookup.lookup(wsdlURI,
adapter.examples.Function.class,
serviceURI);
}
catch (Exception e)
{
e.printStackTrace();
}
// now, call the methods on your Web services interface
return service.getFunction();
}

  结束语

  显然,使用 Web 服务的静态存根与前期绑定是 Web 服务调用的最简单的形式。但是简单化也带来了明显的缺点。与紧耦合方法不同,使用本文提出的适配器方法将给您留下可高度重用和可配置的 Web 服务代码。由于 Web 服务 调用全部通过部署了服务描述符的公共适配器来引导,因此您能够动态地决定调用什么服务——在部署代码时或在运行时。

  同样,那些可能寻找商业产品作为 Web 服务松耦合调用定制解决方案的组织应该研究企业服务总线(Enterprise Service Bus,ESB)技术,该技术提供了类似于上面所引述的功能的选项来连接企业内部及跨企业的可作为 Web 服务的应用程序,并具备一套功能来管理并监视已连接应用之间的交互。

6页,页码:[1] [2] [3] [4] [5] [6] 

上一篇:通过CCNA认证就可以通过Network+认证吗?
下一篇:玩的就是虚的--用SoftEther建造虚拟局域网
作者:Mark M.Davydov  来源:developerWorks 中国 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐