使用已知但无法访问的 wsdl 创建 Web 服务客户端 [英] Creating a web-service client with a known but inaccessible wsdl
问题描述
与我们合作的一家公司通过电子邮件向我们提供了 wsdl 和 xsd 架构.我们所连接的网络服务是通过 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.
第二个问题:是否有一种简单的方法可以将其路由到不同的soap地址?
2nd Question: Is there an easy way to route this to a different soap address?
我只想能够做这样的事情:
I just want to be able to do something like:
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.
我错过了什么吗?
*回应斯卡夫曼:这就是生成的.它默认为 wsdlLocation 作为名称 shrug
*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:Address 的本地 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.
编辑我发现您可以通过编程方式更改端点地址,而无需更改实际的 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屋!