使用已知但无法访问的wsdl创建Web服务客户端 [英] Creating a web-service client with a known but inaccessible wsdl

查看:311
本文介绍了使用已知但无法访问的wsdl创建Web服务客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通过电子邮件与我们合作的公司提供了wsdl和xsd架构。我们正在连接的Web服务是通过IPsec隧道访问的。在已发布的WSDL中有本地引用(在它们的末尾),这意味着我们无法使用它。

We have been provided with a wsdl and xsd schema by a company we are working with via email. The web-services we are interfacing with are accessed through a IPsec tunnel. There are local references(on their end) in the published WSDL which means we cannot consume it.

第一个问题:这是一个常见的设置吗?我认为拥有WSDL不仅要定义合同,还要将服务公开给消费者。

1st question: Is this a common setup? I thought the point of having a WSDL was not only to define the contract but to also expose the service to consumers.

我可以轻松生成客户端/服务器代码使用wsimport,wsconsume等提供WSDL。我知道当我生成的客户端调用我生成的服务时,它会生成我需要的正确消息。

I can easily generate client/server code off of the provided WSDL using wsimport, wsconsume, etc.. I know when my generated client makes a call to my generated service it produces the correct message I need.

第二个问题:是有一种简单的方法可以将其路由到不同的肥皂地址吗?

2nd Question: Is there an easy way to route this to a different soap address?

我只想做类似的事情:

SalesTaxService svc = new SalesTaxService();
SalesTax tax = svc.getSalesTaxPort()
tax.getRate("NY");

但不要使用WSDL中定义的soap地址。我想避免为每种方法编写一堆调度客户端。

But not use the soap address defined in the WSDL. I would like to avoid writing a bunch of dispatch clients for each method.

我错过了什么吗?

*响应skaffman:
这就是生成的内容。它默认为wsdlLocation为名称​​耸肩

*In response to skaffman: This is what was generated. It defaulted to wsdlLocation as a name shrug

   @WebServiceClient(name = "SomeService")
   public class SomeService_Service extends Service {

    public SomeService_Service(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);            
    }

    public SomeService_Service(URL wsdlLocation) {
        super(wsdlLocation, new QName("urn:some_service", "SomeService"));   
    }
  }


推荐答案

所以我弄清楚为什么我遇到了问题。我假设wsdlLocation必须是实际服务发布的WSDL。当然情况并非如此。解决方案是使用正确的SOAP:本地WSDL将实际服务的地址打包到客户端。

So I figured out why I was having a problem. I was assuming that the wsdlLocation had to be the WSDL that the actual service was publishing. This of course is not the case. The solution is to package a local WSDL with the correct SOAP:Address for the actual service into the client.

编辑
I发现您可以以编程方式更改端点地址,而无需更改实际的WSDL:

edit I found out that you can alter the endpoint address programmatically without having to alter the actual WSDL:

HelloService service = new HelloService (
  this.getClass().getResource("originalHello.wsdl"),
  new QName("http://example.org/hello", "HelloService "));
HelloPort proxy = service.getHelloPort();

Map<String, Object> ctxt = ((BindingProvider)proxy ).getRequestContext();
ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://new/endpointaddress");

proxy.sayHello("Hello World!");

信用证转到:李建明

这篇关于使用已知但无法访问的wsdl创建Web服务客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆