我對SOAP很新穎,而且我正在努力爲服務器創建一個SOAP POST請求。我有以下示例請求: -在JAVA中創建一個SOAP POST
POST /sso/ArtifactResolver/metaAlias/assert-idp
HTTP/1.1
Host:xxx
Content-Type: text/xml
Content-Length:
SOAPAction:http://....
,這裏是我的SOAP Envevelop
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<samlp:ArtifactResolve
xmlns:samlp="xxxxxxxxxxxxxx"
xmlns="xxxxxxxxxxx"
ID="_6c3a4f8b9c2d"
25 March 2014 Page 30
(APPROVED – Version 1.1)
Version="2.0"
IssueInstant="2012-05-21T00:39:45Z">
<Issuer>https://www.xxxxxxxxxxxxxx</Issuer>
<Artifact>
AAQAABWFTOPhANZhf21nl9DmXsAkiSM0ocx7GdxUfXFttmS954 BP6Vb01I0=
</Artifact>
</samlp:ArtifactResolve>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
下面是我的Java代碼我想使用: -
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMsg = factory.createMessage();
SOAPPart part = soapMsg.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
SOAPBodyElement element = body.addBodyElement(envelope.createName("ArtifactResolve", "sampl", "xxxxxxxxxxxx"));
element.addChildElement("Issuer").addTextNode("xxxxxxxxxxx");
element.addChildElement("Artifact").addTextNode("xxxxxxxxxxxx");
element.setAttribute("xmlns", "xxxxxxxxxxxxx");
element.setAttribute("ID", "xxxxxxxxx");
element.setAttribute("Version", "2.0");
element.setAttribute("IssueInstant", "xxxxxxxxxx");
PostMethod post = new PostMethod("PUT Server Url");
// Request content will be retrieved directly from the input stream
post.setRequestEntity(entity);
// consult documentation for your web service
post.setRequestHeader("SOAPAction", "**what to put here????**");
// Get HTTP client
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
}
現在在上面的代碼在哪裏指定服務器的URL? 二是如何通過完整的XML XML發佈請求? 如何傳遞給出的頂部POST數據? 什麼給肥皂行動?
對不起,這傢伙買我完全是新的這個,所以不知道。 我試圖通過互聯網尋找這個,但沒有幫助。
請幫我在這裏
謝謝...
正如您的示例中所建議的那樣,URL端點會進入新的PostMethod(「xxx」)。該請求使用'SOAPBodyElement element = body ...'構建。 SOAP操作在你的WSDL中被描述爲綁定。我建議你檢查這個SO帖子http://stackoverflow.com/questions/19291283/soap-request-to-webservice-with-java –
謝謝你回覆安東尼科拉多,但我沒有一個Web服務的網址 – Vishesh