java - 在 JAVA 中创建 SOAP POST

标签 java soap

我对 SOAP 还很陌生,并且正在努力创建对服务器的 SOAP POST 请求。我有以下示例请求:-

POST /sso/ArtifactResolver/metaAlias/assert-idp
HTTP/1.1
Host:xxx
Content-Type: text/xml
Content-Length: 
SOAPAction:http://....

这是我的 SOAP 信封

<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? 其次是如何将完整的soap XML传递给post请求? 如何传递给定的顶部 POST 数据? SOAP 作用要给予什么?

抱歉,这些人买了,我对此完全陌生,所以不知道。 我尝试在互联网上寻找此内容,但没有帮助。

请帮帮我

谢谢...

最佳答案

按照示例中的建议,URL 端点位于 new PostMethod("xxx") 中。

该请求是使用 SOAPBodyElement element = body... 构建的。

SOAP 操作在您的 WSDL 中描述为绑定(bind)。

我建议你查看这个帖子SOAP request to WebService with java

关于java - 在 JAVA 中创建 SOAP POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33532841/

相关文章:

java - 如何将 byte[] 附加到 List<Byte>?

没有 WCF 的 C# SOAP 服务

java - 使用 JAXB 通过 SOAP 传递 HashMap<String,Object>

java - 在 GWT/Spring MVC 中处理 SOP - Rest

Java 队列 - 为什么 "poll"和 "offer"?

java - 无法在 Java 应用程序中的 SODA 中添加的文档存储上进行 SELECT

java - vararg 参数可以是 <? super 对象>?

delphi - 无法在 Delphi 中为 VIES SOAP 服务加载 WSDL 文件/位置

java - 如何通过需要身份验证的代理发送 SOAP 消息?

asp.net - Web 服务需要一个 DataSet 对象,我如何通过 ColdFusion 或原始 XML 提供该对象?