使用SOAPConnectionFactory清理soap请求

时间:2015-08-19 14:12:24

标签: java web-services soap

我对肥皂非常陌生,我在这里找到了一个如何处理请求的示例:Working Soap client example

使用Chrome插件我设法找到一个可用的肥皂查询字符串:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
    <GetMyProjectCharges xmlns="http://company.IWWeb.Data.Service.ProjectCharges">
        <Employee>26270</Employee>
        <FiscalYear>2015</FiscalYear>
        <ApiKey>APIKEY</ApiKey>
        <AppName>APPNAME</AppName>
        </GetMyProjectCharges>
</Body>
</Envelope>

所以尝试从我写的堆栈帖子中发布的代码:

 private static SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://schemas.xmlsoap.org/soap/envelope/";

    // SOAP Envelope

    SOAPEnvelope envelope = soapPart.getEnvelope();

    /*
    Constructed SOAP Request Message:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
        <SOAP-ENV:Header/>
        <SOAP-ENV:Body>
            <example:VerifyEmail>
                <example:email>mutantninja@gmail.com</example:email>
                <example:LicenseKey>123</example:LicenseKey>
            </example:VerifyEmail>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
     */

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();

    SOAPElement soapBodyElem = //soapBody.addChildElement("GetMyProjectCharges");

    soapBody.addChildElement("GetMyProjectCharges", "", "http://company.IWWeb.Data.Service.ProjectCharges");

    SOAPElement soapBodyEmployee = soapBodyElem.addChildElement("Employee").addTextNode("26270");
    SOAPElement soapBodyFiscalYear = soapBodyElem.addChildElement("FiscalYear").addTextNode("2015");
    SOAPElement soapBodyAPIKey = soapBodyElem.addChildElement("ApiKey").addTextNode("APIKEY");
    SOAPElement soapBodyAppName = soapBodyElem.addChildElement("AppName").addTextNode("APPNAME");


    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI  + "GetMyProjectCharges");

    soapMessage.saveChanges();

    /* Print the request message */
    System.out.print("Request SOAP Message:");
    soapMessage.writeTo(System.out);
    System.out.println();

    return soapMessage;
}

但是,我最终会收到以下肥皂请求代码:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <GetMyProjectCharges xmlns="http://company.IWWeb.Data.Service.ProjectCharges">
            <Employee>26270</Employee>
            <FiscalYear>2015</FiscalYear>
            <ApiKey>APIKEY</ApiKey>
            <AppName>APPNAME</AppName>
        </GetMyProjectCharges>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

服务器似乎并不高兴。有没有一种简单的方法来修改我正在做的事情,以使查询字符串更接近我想要的?

0 个答案:

没有答案