WS Client: Set Endpoint Address in JAX-WS Client

本文介绍如何在JAX-WS客户端中通过多种方式设置新的端点地址,包括直接在构造Service实例时指定新地址、使用BindingProvider.ENDPOINT_ADDRESS_PROPERTY属性覆盖原有地址,以及从本地文件加载WSDL来解决原始WSDL不可用的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Set Endpoint Address in JAX-WS Client
 Example:
1 try{
2 HelloServiceservice=newHelloService(
3 newURL("http://new/endpointaddress?wsdl"),
4 newQName("http://example.org/hello","HelloService"));
5 }catch(MalformedURLExceptione){
6 log.fatal(e);
7 }
8
9 HelloPortproxy=service.getHelloPort();
10 proxy.sayHello("HelloWorld!");
11

You can use BindingProvider.ENDPOINT_ADDRESS_PROPERTY to override endpoint address. One caveat is the original endpoint used to generated the client proxy need to be up, otherwise you'll get a nasty "java.net.ConnectException: Connection refused" exception when instantiating the Service at the first place.

1 //CreateserviceandproxyfromthegeneratedServiceclass.
2 HelloServiceservice=newHelloService();
3 HelloPortproxy=service.getHelloPort();
4
5 Map<String,Object>ctxt=((BindingProvider)proxy).getRequestContext();
6 ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE,8192);
7 ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"http://new/endpointaddress");
8
9 proxy.sayHello("HelloWorld!");
10

Use a local wsdl placed in classpath to create service and port, then set new end point address. This solves the issue that the original wsdl can NOT be be obtained from a live server and the live wsdl has a different service name, for example as a result of service virtualization.

1 HelloServiceservice=newHelloService(
2 this.getClass().getResource("originalHello.wsdl"),
3 newQName("http://example.org/hello","HelloService"));
4
5 Map<String,Object>ctxt=((BindingProvider)proxy).getRequestContext();
6 ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE,8192);
7 ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"http://new/endpointaddress");
8
9 proxy.sayHello("HelloWorld!");
10

Declaration:

This doc is a copy from http://jianmingli.com/wp/?p=585

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值