3

jQueryAjaxを使用してasmxサービスを呼び出そうとしています。

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>

上記は、サービスに送信する必要のあるSOAP1.1リクエストです。以下の呼び出しを使用して、カスタムの石鹸ヘッダーを設定しています。しかし、私の要求は失敗します。誰かが私のために以下のコードをデバッグして、私が何をする必要があるかを私に知らせてもらえますか?

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
});

編集*この質問に答えるために追加情報が必要な場合はお知らせください。*

4

2 に答える 2

5

jQuery.ajax().NET Webサービスだけでなく、あらゆるタイプの「Webサービス」に対して汎用HTTP要求を発行します。SOAPActionリクエストヘッダーを追加し、SOAPエンベロープ全体をPOSTデータとして渡す必要があります。

$.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
});

beforeSendjQuery <1.5を使用している場合は、SOAPActionリクエストヘッダーを設定するためにを使用する必要があります。

のドキュメントはjQuery.ajax()http://api.jquery.com/jQuery.ajax/あります。

于 2012-06-11T17:09:50.520 に答える
1

これらを追加し忘れたようです:

contentType: 'text/xml; charset=utf-8',
dataType: 'xml'

これらの2行を追加した後、 Seleniumでデバッグするのに問題なく機能します。

于 2012-06-17T11:08:35.780 に答える