soap 报文中添加自定义命名空间

var code = "d4653cd9-b58b-4e0f-9eed-76028da0a7f7"

默认生成的报文

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header/>
   <soap:Body>
      <ns2:xx_xx_xx_xx>

预期报文

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yyyy="http://www.xxx.xx.xx">
   <soapenv:Header/>
   <soapenv:Body>
      <ns2:xx_xx_xx_xx>

报文生成方式为 

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress(url);
// for SOAP 1.2
factory.setBindingId(SoapBindingConstants.SOAP11_BINDING_ID);
factory.setServiceClass(clazz);
T webService = (T) factory.create();

Client proxy = ClientProxy.getClient(webService);
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HashMap<String, String> hmap = new HashMap<String, String>();
hmap.put("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
hmap.put("xxx", "http://xx.xx.xxx.xxx");
if (CollUtil.isNotEmpty(hmap)) {
    proxy.getRequestContext().put("soap.env.ns.map", hmap);
    proxy.getRequestContext().put("disable.outputstream.optimization", "true");
}

后记

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xxxx="http://xxxx.xxxx.xxxx/xxx/xxx">
    <soapenv:Body>
        <xxxx:xxxx_xxx_xx_xxx>

需要在接口中添加 targetNamespace="http://xxxx.xxxx.xxxx/xxx/xxx" 这个地址要和 hmap.put("xxxx", "http://xxxx.xxxx.xxxx/xxx/xxx"); 中写的一样

@WebService(name = "xxxx_xxx_xx_xxx", targetNamespace="http://xxxx.xxxx.xxxx/xxx/xxx")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface XxxYxxxxYxxxSend {
    @WebMethod(operationName = "xxxx_xxx_xx_xxx", action = "http://sap.com/xi/WebService/soap1.1")
    @WebResult(name = "xxxx_xxx_xx_xxx", partName = "xxxx_xxx_xx_xxx")
    XxxYxxxxYxxxSendResponse yyyyyy(
            @WebParam(partName = "xxxx_xxx_xx_xxx", name = "xxxx_xxx_xx_xxx")
                    XxxYxxxxYxxxSendRequest xxxYxxxxYxxxSendRequest
    );
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
webservice响应报文的格式通常是XML格式。XML是一种可扩展标记语言,用于描述数据的结构和内容。在webservice,响应报文的格式遵循SOAP协议,SOAP是一种基于XML的通信协议,用于在网络上交换结构化信息。SOAP协议定义了报文的格式和通信规则,以确保不同平台和系统之间的互操作性。响应报文的格式包含在SOAP Envelope元素,其包含SOAP Header和SOAP Body两个部分。SOAP Header用于传递额外的信息和参数,而SOAP Body包含实际的响应数据。在SOAP Body,响应数据被封装在特定的命名空间下的元素。这些元素的结构和内容由webservice的定义确定,以便客户端可以解析和处理响应数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [WebService soap报文请求返回xml格式以及自定义soap模板](https://blog.csdn.net/zz18435842675/article/details/96869484)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [WebService soap报文请求与响应报文解析(JAVA)](https://blog.csdn.net/qq_27256783/article/details/103660512)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值