如何向SOAP请求添加参数

时间:2014-06-10 06:54:01

标签: java web-services wsdl sap

我想在RFC中调用SAP函数,我已经可以从Java发出请求并获得WSDL响应。但是我想用SOAP请求发送一个参数?怎么做?

下面的课程,我用它来创建请求并获得响应:

public class SOAPClientSAAJ {

    public static void main(String args[]) throws Exception {
        // Create SOAP Connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        // Send SOAP Message to SOAP Server
        String url = "http://10.130.105.8:8000/sap/bc/.....client=520";
        SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

        // print SOAP Response
        System.out.print("Response SOAP Message:");
        soapResponse.writeTo(System.out);
        soapConnection.close();
    }

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

        String serverURI = "http://ws.cdyne.com/";

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("example", serverURI);

            // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement("pernr","example");

        soapBodyElem.addTextNode("10001001");

        String authorization = new String(Base64.encodeBase64(("hr_develop:unrwa2013").getBytes()));

        soapMessage.getMimeHeaders().addHeader("Authorization","Basic " + authorization);
            soapMessage.saveChanges();

        /* Print the request message */
        soapMessage.writeTo(System.out);
        System.out.println();
            return soapMessage;
    }

}

0 个答案:

没有答案
相关问题