java 在 Soap 请求中发送无效的 XML 字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2479838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:23:10  来源:igfitidea点击:

Sending invalid XML Characters in Soap Request

javaxmlsoapaxisescaping

提问by Selvakumar Arumugam

I am trying to send special (&, '(single quote)) characters in the Soap Request. I am using axis 1.4. The webservice client is in weblogic server and the webservice server is an ibm mainframe (COBOL program).

我正在尝试在 Soap 请求中发送特殊 ( &, '(单引号)) 字符。我正在使用轴 1.4。webservice客户端在weblogic server中,webservice server是ibm大型机(COBOL程序)。

The request data from the client contains special character (&symbol) which is converted to &

来自客户端的请求数据包含&转换为特殊字符(符号)&

I tried to enclose it with CDATA as

我试图将它与 CDATA 一起作为

<![CDATA[Some Name & Some Data ]]>which got converted to

<![CDATA[Some Name & Some Data ]]>转换为

&lt;![CDATA[Some Name &amp; Some Data]]&gt; 

The webservice client is generated from wsdl, so I couldn't use CDATA api to construct the request. I am able to set it as string value, and it is getting converted.

webservice 客户端是从 wsdl 生成的,所以我不能使用 CDATA api 来构造请求。我可以将它设置为字符串值,并且它正在被转换。

Any help on this would be greatly appreciated. Please let me know if you need any more information on this.

对此的任何帮助将不胜感激。如果您需要更多信息,请告诉我。

回答by Mads Hansen

The web service client stubs are doing the XML encoding for you. The web service expects XML, and it is encoding the &and 'into entity references so that you will be sending valid XML.

Web 服务客户端存根正在为您进行 XML 编码。Web服务预计XML,它是编码&'成实体引用,这样你会被发送有效的XML。

To an XML parser, it will "see" the &amp;as &and you don't have a problem.

对于 XML 解析器,它会“看到” &amp;as&并且您没有问题。

If the server is unable to handle the entity references, then the COBOL "web service" isn't doing what it is supposed to be doing. That makes it difficult for you(and standards based tools) to generate client stubs from the WSDL, which is essentially a contract that describes the rules for data format and interchange.

如果服务器无法处理实体引用,则 COBOL“Web 服务”没有做它应该做的事情。这使您(和基于标准的工具)难以从 WSDL 生成客户端存根,WSDL 本质上是一种描述数据格式和交换规则的契约。

What is the point of providing a WSDL and a SOAP service if it doesn't adhere to it's prescribed interface rules?

如果不遵守规定的接口规则,提供 WSDL 和 SOAP 服务有什么意义?