2015-11-04 26 views
0

我對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數據? 什麼給肥皂行動?

對不起,這傢伙買我完全是新的這個,所以不知道。 我試圖通過互聯網尋找這個,但沒有幫助。

請幫我在這裏

謝謝...

+0

正如您的示例中所建議的那樣,URL端點會進入新的PostMethod(「xxx」)。該請求使用'SOAPBodyElement element = body ...'構建。 SOAP操作在你的WSDL中被描述爲綁定。我建議你檢查這個SO帖子http://stackoverflow.com/questions/19291283/soap-request-to-webservice-with-java –

+0

謝謝你回覆安東尼科拉多,但我沒有一個Web服務的網址 – Vishesh

回答

0

URL端點進去new PostMethod("xxx")作爲樣本建議。

該請求使用SOAPBodyElement element = body...構建。

SOAP操作在您的WSDL中描述到綁定中。

我建議你檢查這個SO發佈SOAP request to WebService with java

+0

有一個疑問,我有在你給的例子中... //發送SOAP消息到SOAP服務器 String url =「http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx」; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(),url);這是什麼網址???????第二次創建SOAP消息字符串serverURI =「http://ws.cdyne.com/」; // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration(「example」,serverURI);這個URI是什麼? – Vishesh

0

請參閱以下網址 - http://svn.apache.org/repos/asf/httpcomponents/oac.hc3x/trunk/src/examples/PostSOAP.java

這是一個非常具體的例子,我測試了它充分的工作。

現在在上面的代碼中指定服務器url? - 您可以將它作爲命令行參數傳遞,或者在客戶端代碼中傳遞。

二是如何通過完整的soap XML來發布請求? - 該示例接受來自作爲第三個參數傳遞的文件的XML。或者,您可以在客戶端代碼中對XML進行硬編碼。

什麼給肥皂行動?請檢查SOAPAction的WSDL文件。它將按照每種方法列出。請注意,在URL中,您沒有放置任何方法名稱,而只是放置服務URL。那麼如果有很多方法,如何區分它們呢?通過這個SOAPAction。如果有任何方法像「繁殖」,那麼SOAPAction將是「urn:multiply」。

希望這會有所幫助。