这是WSDL中使用的XML,它显示在SOAPUI中。
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bran="BDetail">
<soapenv:Header/>
<soapenv:Body>
<bran:sentIbBTyp soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<pBnCode xsi:type="xsd:string">234</pBnCode>
</bran:sentIbBTyp>
</soapenv:Body>
</soapenv:Envelope>
我用这个java代码传递值
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("xsd",
"http://www.w3.org/2001/XMLSchema");
soapEnvelope.addNamespaceDeclaration("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
soapEnvelope.addNamespaceDeclaration("bran", "BDetail");
SOAPBody soapBody = soapEnvelope.getBody();
SOAPElement soapElement = soapBody.addChildElement(
"sentIbBTyp", "bran");
soapElement
.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
SOAPElement elementBankCode = soapElement.addChildElement("pBnCode");
elementBankCode.setValue("234");
我收到了这个错误。请帮帮我......
SOAP error No Deserializer found to deserialize a ':pBnCode' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'. [java.lang.IllegalArgumentException]
答案 0 :(得分:0)
以下代码可能有所帮助。检查其他QName构造函数并使用适当的构造函数。
将生成的XML与SOAP UI中的工作XML进行比较。
@Test
public void test() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("xsd",
"http://www.w3.org/2001/XMLSchema");
soapEnvelope.addNamespaceDeclaration("xsi",
"http://www.w3.org/2001/XMLSchema-instance");
soapEnvelope.addNamespaceDeclaration("bran", "BDetail");
SOAPBody soapBody = soapEnvelope.getBody();
SOAPElement soapElement = soapBody.addChildElement(
"sentIbBTyp", "bran");
soapElement
.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
SOAPElement elementBankCode = soapElement.addChildElement("pBnCode");
// added missing attribute
QName qname = new QName("xsi:type");
elementBankCode.addAttribute(qname, "xsd:string");
elementBankCode.setValue("234");
soapMessage.writeTo(System.out);
}
我希望这会有所帮助。