[英]SOAP request. Convert string to byte array
I have Soap WS on Java. 我有Java上的Soap WS。
Here is soap request 这是肥皂的要求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:his="SCC/Lis/HistoryFormatter">
<soapenv:Header/>
<soapenv:Body>
<his:formatHistoryByteArray>
<arg0>cid:anystring</arg0>
</his:formatHistoryByteArray>
</soapenv:Body>
</soapenv:Envelope>
FormatHistoryByteArray.class has only one field FormatHistoryByteArray.class只有一个字段
@XmlElement(name = "arg0", namespace = "", nillable = true)
private byte[] arg0;
Type in *.xsd 输入* .xsd
<xs:complexType name="formatHistoryByteArray">
<xs:sequence>
<xs:element name="arg0" type="xs:base64Binary" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
WSDL and xsd is generated by JaxWS. WSDL和xsd由JaxWS生成。
I cann't understand logic of convertion string in 我不明白转换字符串的逻辑 node in request to byte[] in java-code. Java代码中对byte []的请求中的节点。 Help plz 帮助PLZ
cid: is the requared prefix or not? cid:是重新排序的前缀吗?
Edited: for example, if I have request 编辑:例如,如果我有要求
<arg0>abcdef</arg0>
in java code I get byte[] = {105, -73, 29} 在Java代码中我得到byte [] = {105,-73,29}
How WebService get this byte array from string abcdef ? WebService如何从字符串abcdef获取此字节数组?
String.getBytes()
returns you the (ASCII, UTF8, ISO-8859-1 etc.) encoding of a given String
. String.getBytes()
返回给定String
的(ASCII,UTF8,ISO-8859-1等)编码。 That's different from what Base 64 is. 这与Base 64不同。 Base 64 is a way of displaying arbitrary bytes as printable characters. Base 64是一种将任意字节显示为可打印字符的方法。 So there is no reason for them to be the same. 因此,没有理由让它们相同。
Have a look at section 2.1 of this tutorial on Base 64 and XML: http://www.xml.com/pub/a/2003/02/26/binaryxml.html . 请参阅本教程有关Base 64和XML的2.1节: http : //www.xml.com/pub/a/2003/02/26/binaryxml.html 。 The base64 bit looks like this: base64位如下所示:
<m:data xmlns:m='http://example.org/people' >
<photo>/aWKKapGGyQ=</photo>
<sound>sdcfo2JTiXE=</sound>
<hash>Faa7vROi2VQ=</hash>
</m:data>
where photo
etc. are base64 elements. 其中photo
等是base64元素。 cid
prefix is not needed. 不需要cid
前缀。
To address your question, abcdef
is being interpreted by the web service unmarshaller as a base-64 encoded string as the three bytes you received. 为了解决您的问题,Web服务unmarshaller将abcdef
解释为您收到的三个字节的base-64编码字符串。
The schema specifically declares the type as: "xs:base64Binary" aka: BINARY. 该模式专门将类型声明为:“ xs:base64Binary” aka:BINARY。 If you expect the the information to be textual in nature, the type should likely be "xs:string" or similar. 如果您希望信息本质上是文本信息,则类型可能应该是“ xs:string”或类似的类型。
Actually, the service should be rejecting the value of "cid:anystring" entirely. 实际上,该服务应该完全拒绝“ cid:anystring”的值。 That's not a valid value for a base64 encoded element. 对于以base64编码的元素,该值无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.