发送SOAP信封的使用jQuery的Ajax自定义标题自定义、信封、标题、SOAP

2023-09-05 04:37:50 作者:-冷心冷血冷感情°

我想使用jQuery的Ajax调用的ASMX服务

I am trying to call an asmx service using jQuery Ajax.

POST /YderWS.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://scandihealth.com/iwebservices/HentKommuner"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthHeader xmlns="http://scandihealth.com/iwebservices/">
      <PartnerID>string</PartnerID>
      <SubPartnerID>string</SubPartnerID>
      <SubPartnerType>string</SubPartnerType>
    </AuthHeader>
  </soap:Header>
  <soap:Body>
    <HentKommuner xmlns="http://scandihealth.com/iwebservices/" />
  </soap:Body>
</soap:Envelope>

以上是SOAP 1.1请求我需要发送到服务。我现在用的是下面的调用来设置自定义SOAP头。但我的请求失败。任何人都可以调试低于code对我来说,让我知道什么,我需要做什么?

Above is the SOAP 1.1 request I need to send to the service. I am using the below call to set the custom soap header. But my request fails. Can anybody debug the below code for me and let me know what I need to do?

var authHeader = "<PartnerID>SCTEST001</PartnerID> <SubPartnerID>001</SubPartnerID> <SubPartnerType>S</SubPartnerType>";
//Call the page method
$.ajax({
  type: "GET",
  url: servicename + "/" + functionName,
  beforeSend: function (xhr) {
    xhr.setRequestHeader('AuthHeader', authHeader);
  },
  success: successFn,
  error: errorFn
});

修改 *的请让我知道,如果需要更多信息来回答这个问题。的*

推荐答案

jQuery.ajax()问题的任何类型的Web服务的通用的HTTP请求,而不仅仅是.NET Web服务。你要添加的SOAPAction请求头,并通过整个SOAP信封POST数据:

jQuery.ajax() issues generic HTTP requests for any type of "web service", not just .NET web services. You'll want to add a SOAPAction request header and pass the entire SOAP envelope as POST data:

$.ajax({
    type: 'POST',
    url: servicename + "/" + functionName,
    contentType: 'text/xml; charset=utf-8',
    headers: {
        SOAPAction: 'http://scandihealth.com/iwebservices/HentKommuner'
    },
    data: '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><AuthHeader xmlns="http://scandihealth.com/iwebservices/"><PartnerID>string</PartnerID><SubPartnerID>string</SubPartnerID><SubPartnerType>string</SubPartnerType></AuthHeader></soap:Header><soap:Body><HentKommuner xmlns="http://scandihealth.com/iwebservices/" /></soap:Body></soap:Envelope>',
    success: successFn,
    error: errorFn
});

如果您正在使用jQuery&LT; 1.5,你需要使用 beforeSend 设定的SOAPAction请求头。

If you're using jQuery < 1.5, you'll need to use beforeSend to set the SOAPAction request header.

您可以找到的文档jQuery.ajax()在的 http://api.jquery.com/jQuery.ajax/ 。