我試圖發送SOAP消息。發送SOAP消息
我加入手動頭的消息,使用下面的代碼:
public static void main(String[] args) {
try{
AmdocsServicesServiceagentLocator locator = new AmdocsServicesServiceagentLocator();
PortTypeEndpoint1BindingStub port = new PortTypeEndpoint1BindingStub(new URL("http://srvp7rd-tibco.rnd.local:8025/Process/SoapRequests/Amdocs-Services.serviceagent/PortTypeEndpoint1"),locator);
GetContactRelatedInfo parameters = new GetContactRelatedInfo();
GetContactRelatedInfoRequest request = new GetContactRelatedInfoRequest();
request.setPersonID("6610782925");
request.setPersonIDType("ID number (CPR)");
/* Creating an empty XML Document - We need a document*/
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
/* Creating the XML tree */
/* Create the root element and add it to the document */
Element root = doc.createElement("mul:MultiTenant");
doc.appendChild(root);
/* Adding the child to the root */
Element child = doc.createElement("mul:OpCo");
root.appendChild(child);
/* Add text element to the child */
Text text = doc.createTextNode("DENMARK");
child.appendChild(text);
/* Adding the child to the root */
child = doc.createElement("mul:BS");
root.appendChild(child);
/* Add text element to the child */
text = doc.createTextNode("ENV3");
child.appendChild(text);
SOAPHeaderElement element = new SOAPHeaderElement("" ,"soapenv:Header" , doc);
element.setActor(null);
port.setHeader(element);
System.out.println(port.getHeaders()[0]);
port.getContactRelatedInfoOperation(parameters);
} catch (Exception e){
e.printStackTrace();
}
}
但我不知道爲什麼,或者我是如何結束了包括我沒有」屬性的消息不想要。 例如當前代碼的輸出信息是:
<soapenv:Header soapenv:mustUnderstand="0" xsi:type="ns1:Document"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns1="http://xml.apache.org/xml-soap">
<mul:MultiTenant xmlns:mul="">
<mul:OpCo xmlns:mul="">DENMARK</mul:OpCo>
<mul:BS xmlns:mul="">ENV3</mul:BS>
</mul:MultiTenant></soapenv:Header>
例如,在mul:OpCo
標籤的xmlns:mul=""
屬性。 有沒有辦法刪除該屬性?
頭看起來應該是: < - 可選:! - > ?可選: - > ? mul:MultiTenant> soap:Header> –
2012-02-08 14:55:21
@Tal:這不是有效的XML。你*必須*聲明'mul'命名空間。 – skaffman 2012-02-08 15:10:44
那麼如何在不必處理命名空間的情況下添加「mul」呢? – 2012-02-08 15:10:53