如何更改 Web 服务 url 端点?

发布于 2024-11-16 02:53:23 字数 194 浏览 2 评论 0原文

我使用 JBoss utils(JAX-WS 兼容)生成了一个 Web 服务客户端 使用 Eclipse“来自 wsdl 的 Web 服务客户端”。

因此,我唯一提供的就是 Web 服务 WSDL 的 URL。

现在,Web 服务提供商告诉我更改 Web 服务的“客户端端点应用程序访问的 URL”。

它是什么以及如何改变它?

I generated a web-service client using JBoss utils (JAX-WS compatible)
using Eclipse 'web service client from a wsdl'.

So, the only thing I provided was a url to a web-service WSDL.

Now, the web service provider tells me to change the "url of client endpoint application access" of the web-service.

What is it and how to change it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦回梦里 2024-11-23 02:53:23

IMO,提供商告诉您更改服务端点(即到达 Web 服务的位置),而不是客户端端点(我不明白这可能是什么)。要更改服务端点,您基本上有两种选择。

使用 Binding Provider 设置端点 URL

第一个选项是更改 BindingProvider.ENDPOINT_ADDRESS_PROPERTYBindingProvider 属性值(每个代理都实现 javax.xml.ws .BindingProvider 接口):

...
EchoService service = new EchoService();
Echo port = service.getEchoPort();

/* Set NEW Endpoint Location */
String endpointURL = "http://NEW_ENDPOINT_URL";
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);

System.out.println("Server said: " + echo.echo(args[0]));
...

缺点是这仅在原始 WSDL 仍可访问时才有效。不推荐。

使用 WSDL 获取端点 URL

第二个选项是从 WSDL 获取端点 URL。

...
URL newEndpoint = new URL("NEW_ENDPOINT_URL");
QName qname = new QName("http://ws.mycompany.tld","EchoService"); 

EchoService service = new EchoService(newEndpoint, qname);
Echo port = service.getEchoPort();

System.out.println("Server said: " + echo.echo(args[0]));
...

IMO, the provider is telling you to change the service endpoint (i.e. where to reach the web service), not the client endpoint (I don't understand what this could be). To change the service endpoint, you basically have two options.

Use the Binding Provider to set the endpoint URL

The first option is to change the BindingProvider.ENDPOINT_ADDRESS_PROPERTY property value of the BindingProvider (every proxy implements javax.xml.ws.BindingProvider interface):

...
EchoService service = new EchoService();
Echo port = service.getEchoPort();

/* Set NEW Endpoint Location */
String endpointURL = "http://NEW_ENDPOINT_URL";
BindingProvider bp = (BindingProvider)port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURL);

System.out.println("Server said: " + echo.echo(args[0]));
...

The drawback is that this only works when the original WSDL is still accessible. Not recommended.

Use the WSDL to get the endpoint URL

The second option is to get the endpoint URL from the WSDL.

...
URL newEndpoint = new URL("NEW_ENDPOINT_URL");
QName qname = new QName("http://ws.mycompany.tld","EchoService"); 

EchoService service = new EchoService(newEndpoint, qname);
Echo port = service.getEchoPort();

System.out.println("Server said: " + echo.echo(args[0]));
...
波浪屿的海角声 2024-11-23 02:53:23

在此添加一些说明,当您创建服务时,服务类使用默认的“wsdlLocation”,该类是在从 wsdl 构建该类时插入的。因此,如果您有一个名为 SomeService 的服务类,并且创建一个如下所示的实例:

SomeService someService = new SomeService();

如果您查看 SomeService 内部,您将看到构造函数如下所示:

public SomeService() {
        super(__getWsdlLocation(), SOMESERVICE_QNAME);
}

因此,如果您希望它指向另一个 URL,只需使用构造函数它接受一个 URL 参数(还有 6 个构造函数用于设置 qname 和功能)。例如,如果您设置了一个正在侦听端口 9999 的本地 TCP/IP 监视器,并且您想要重定向到该 URL:,

URL newWsdlLocation = new URL("http://theServerName:9999/somePath");
SomeService someService = new SomeService(newWsdlLocation);

那么这将在服务内调用此构造函数:

public SomeService(URL wsdlLocation) {
    super(wsdlLocation, SOMESERVICE_QNAME);
}

To add some clarification here, when you create your service, the service class uses the default 'wsdlLocation', which was inserted into it when the class was built from the wsdl. So if you have a service class called SomeService, and you create an instance like this:

SomeService someService = new SomeService();

If you look inside SomeService, you will see that the constructor looks like this:

public SomeService() {
        super(__getWsdlLocation(), SOMESERVICE_QNAME);
}

So if you want it to point to another URL, you just use the constructor that takes a URL argument (there are 6 constructors for setting qname and features as well). For example, if you have set up a local TCP/IP monitor that is listening on port 9999, and you want to redirect to that URL:

URL newWsdlLocation = new URL("http://theServerName:9999/somePath");
SomeService someService = new SomeService(newWsdlLocation);

and that will call this constructor inside the service:

public SomeService(URL wsdlLocation) {
    super(wsdlLocation, SOMESERVICE_QNAME);
}
郁金香雨 2024-11-23 02:53:23

我不会像 @Femi 那样更改现有的地址属性。您可以轻松地将新服务添加到定义部分。

<wsdl:service name="serviceMethodName_2">
  <wsdl:port binding="tns:serviceMethodNameSoapBinding" name="serviceMethodName">
    <soap:address location="http://new_end_point_adress"/>
  </wsdl:port>
</wsdl:service>

这不需要将 WSDL 重新编译为 Java,并且更新并不比使用 BindingProvider 选项(顺便说一句,这对我不起作用)更困难。

I wouldn't go so far as @Femi to change the existing address property. You can add new services to the definitions section easily.

<wsdl:service name="serviceMethodName_2">
  <wsdl:port binding="tns:serviceMethodNameSoapBinding" name="serviceMethodName">
    <soap:address location="http://new_end_point_adress"/>
  </wsdl:port>
</wsdl:service>

This doesn't require a recompile of the WSDL to Java and making updates isn't any more difficult than if you used the BindingProvider option (which didn't work for me btw).

明月夜 2024-11-23 02:53:23

要更改结束地址属性,请编辑您的 wsdl 文件

<wsdl:definitions.......
  <wsdl:service name="serviceMethodName">
    <wsdl:port binding="tns:serviceMethodNameSoapBinding" name="serviceMethodName">
      <soap:address location="http://service_end_point_adress"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

To change the end address property edit your wsdl file

<wsdl:definitions.......
  <wsdl:service name="serviceMethodName">
    <wsdl:port binding="tns:serviceMethodNameSoapBinding" name="serviceMethodName">
      <soap:address location="http://service_end_point_adress"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文