JavaScript SOAP请求

时间:2014-01-16 12:01:24

标签: javascript soap wsdl

我正在搜索并尝试了几天,我似乎无法破解它。也许我只是没有看到树木的福雷斯特,但如果有人可以帮我解决这个问题,我将非常感激。 我需要向服务器发送SOAP请求。当我发送HTTP请求时,我得到一个如下所示的XML:

xmlns:i0="http://my.api.com/api.svc?wsdl"
  xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
  xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
  xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
  xmlns:wsa10="http://www.w3.org/2005/08/addressing"
  xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
  xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
  <wsp:Policy wsu:Id="My_API_Endpoint_Secure_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:TransportBinding
          xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <wsp:Policy>
            <sp:TransportToken>
              <wsp:Policy>
                <sp:HttpsToken RequireClientCertificate="false"/>
              </wsp:Policy>
            </sp:TransportToken>
            <sp:AlgorithmSuite>
              <wsp:Policy>
                <sp:Basic256/>
              </wsp:Policy>
            </sp:AlgorithmSuite>
            <sp:Layout>
              <wsp:Policy>
                <sp:Strict/>
              </wsp:Policy>
            </sp:Layout>
          </wsp:Policy>
        </sp:TransportBinding>
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>
  <wsdl:import namespace="http://my.api.com/api.svc?wsdl" location="http://my.api.com/api.svc?wsdl"/>
  <wsdl:types/>
  <wsdl:binding name="My_API_Endpoint_Secure" type="i0:IApi">
    <wsp:PolicyReference URI="#My_Api_Endpoint_Secure_policy"/>
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="StartSession">
      <soap:operation soapAction="http://tempuri.org/ISession/StartSession" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="StartApplication">
      <soap:operation soapAction="http://tempuri.org/ISession/StartApplication" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>

现在我需要调用方法StartSession(),我无法将正确的请求放在一起。我错过了什么?

function soapRequest(){

    var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', APIurl, true);

        var request = '<?xml version="1.0" encoding="utf-8"?>' +
                '<soapenv:Envelope ' + 
                    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                    'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
                    'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                    'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
                    '<soapenv:Body>' +
                            '<wsdl:operation name="StartSession">'+
                                '<soap:operation soapAction="http://tempuri.org/ISession/StartSession" style="document"/>' +
                            '<wsdl:input>' +
                                '<soap:body use="literal">APIkey<soap:body>' +
                            '</wsdl:input>' +

                        '</wsdl:operation>' +
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';

        xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {

                        console.log('done use firebug to see response');
                    }
                }
            }
            // Send the POST request
        xmlhttp.setRequestHeader('Content-Type', 'text/xml');
        xmlhttp.send(request);
};

0 个答案:

没有答案