こんにちは、WSDL サービスを送信するための SOAP メッセージを作成するための Java コードがあります。コードは次のとおりです。
SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage sm = mf.createMessage();
SOAPHeader sh = sm.getSOAPHeader();
SOAPBody sb = sm.getSOAPBody();
QName bodyName = new QName("SendSMSInput");
SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);
QName expiryDate = new QName("EXPIRY_DATE");
SOAPElement node = bodyElement.addChildElement(expiryDate);
node.addTextNode("TARIH GELECEK BURAYA");
QName message_class = new QName("MESSAGE_CLASS");
SOAPElement node2 = bodyElement.addChildElement(message_class);
node2.addTextNode("MESSAGE_CLASS GELECEK BURAYA");
QName s_date = new QName("S_DATE");
SOAPElement node3 = bodyElement.addChildElement(s_date);
node3.addTextNode("S_DATE GELECEK BURAYA");
QName short_number = new QName("SHORT_NUMBER");
SOAPElement node4 = bodyElement.addChildElement(short_number);
node4.addTextNode("SHORT NUMBER GELECEK BURAYA");
QName src_msisdn = new QName("SRC_MSISN");
SOAPElement node5 = bodyElement.addChildElement(src_msisdn);
node5.addTextNode("BOŞLUK");
QName to_rec = new QName("TO_RECEIVERS");
SOAPElement node6 = bodyElement.addChildElement(to_rec);
QName msisdn = new QName("msisdn");
SOAPElement node6_1 = node6.addChildElement(msisdn);
node6_1.addTextNode("BOŞLUK");
QName message_body = new QName("MESSAGE_BODY");
SOAPElement node7 = bodyElement.addChildElement(message_body);
QName message = new QName("message");
SOAPElement node7_1 = node7.addChildElement(message);
node7_1.addTextNode("BOŞLUK");
これにより、次が生成されます。
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SendSMSInput>
<EXPIRY_DATE>TARIH GELECEK BURAYA</EXPIRY_DATE>
<MESSAGE_CLASS>MESSAGE_CLASS GELECEK BURAYA</MESSAGE_CLASS>
<S_DATE>S_DATE GELECEK BURAYA</S_DATE>
<SHORT_NUMBER>SHORT NUMBER GELECEK BURAYA</SHORT_NUMBER>
<SRC_MSISN>BOŞLUK</SRC_MSISN>
<TO_RECEIVERS>
<msisdn>BOŞLUK</msisdn>
</TO_RECEIVERS>
<MESSAGE_BODY>
<message>BOŞLUK</message>
</MESSAGE_BODY>
</SendSMSInput>
</SOAP-ENV:Body>
ヘッダーの下に要素を追加する必要があります。やってみると
QName tokenHeader = new QName("token");
SOAPHeaderElement tokenElement = sh.addHeaderElement(tokenHeader);
それは言います:
HeaderElements must be namespace qualified
Exception in thread "main" com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: HeaderElements must be namespace qualified
at com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl.addHeaderElement(HeaderImpl.java:96)
at soapgenerator.SOAPGenerator.main(SOAPGenerator.java:34)
どうすればこれを達成できますか?