2017-01-02 122 views
0

我試圖與這個Java代碼SOAP調用:SOAP請求使用Java - 請求調用格式問題

SOAPEnvelope envelope = soapPart.getEnvelope(); 
envelope.addNamespaceDeclaration("UserAuthentication", serverURI); 
SOAPBody soapBody = envelope.getBody(); 
SOAPElement soapBodyElem = soapBody.addChildElement("UserAuthentication", "UserAuthentication"); 
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("user_name", "UserAuthentication"); 
soapBodyElem1.addTextNode("[email protected]"); 
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("password", "UserAuthentication"); 
soapBodyElem2.addTextNode("123"); 
soapMessage.saveChanges(); 

SOAP調用所需的格式(我試圖產生)是:

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <UserAuthentication xmlns="http://tempuri.org/"> 
     <user_name>string</user_name> 
     <password>string</password> 
    </UserAuthentication> 
    </soap:Body> 
</soap:Envelope> 

但是通過我的代碼生成的實際通話不符合要求的格式,並在接收端被拒絕,我試圖找出原因以及如何解決它:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:UserAuthentication="http://XXX.XXX.XXX.XXX:XXXX/Logininfo.asmx?op=UserAuthentication"> 
<SOAP-ENV:Header/> 
<SOAP-ENV:Body> 
<UserAuthentication:UserAuthentication> 
<UserAuthentication:user_name>[email protected]</UserAuthentication:user_name> 
<UserAuthentication:password>123</UserAuthentication:password> 
</UserAuthentication:UserAuthentication> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

回答

0

來自接收端的錯誤信息是什麼?

在任何情況下,UserAuthentication元素的命名空間都不相同。

預計:http://tempuri.org/
實際:http://XXX.XXX.XXX.XXX:XXXX/Logininfo.asmx?op=UserAuthentication

+0

錯誤自帶的客戶端頭問題 –

+0

你能具體說說嗎? –

+0

響應:<?xml version =「1.0」encoding =「UTF-8」?> soap:Client服務器沒有RECO gnize HTTP頭的SOAPAction的值:

0
envelope.addNamespaceDeclaration("UserAuthentication", serverURI); 

爲什麼當給你想要的請求不被需要的時候你還說命名空間?

嘗試刪除該行。那麼這一個:

SOAPElement soapBodyElem = soapBody.addChildElement("UserAuthentication", "UserAuthentication"); 

讓它:

QName bodyName = new QName("http://tempuri.org/", 
    "UserAuthentication", "m"); 
SOAPElement soapBodyElem = soapBody.addChildElement(bodyName);