3

wsHTTPBindingとbasicHTTPBindingを介して公開されるwcfWebサービスがあります。後者は、次のように、エンドポイントアドレスを「/basic」として指定します。

    <endpoint address="/basic" binding="basicHttpBinding" bindingConfiguration="theAwesomeBasicHttpServerBinding" contract="LOServices.Proxy.ServiceContracts.ILOService">
      <identity>
        <servicePrincipalName value="HTTP/MY_MACHINE_NAME" />
      </identity>
    </endpoint>

バインディングは次のように定義されます。

  <basicHttpBinding>
    <binding name="theAwesomeBasicHttpServerBinding" maxReceivedMessageSize="5000000">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>

jqueryを使用してWebメソッドの1つを呼び出そうとしています。これはbasicHTTPBindingを超えており、RESTfulではないため、JSONは使用しません。その結果、wcfテストクライアントを介してサービスに対して行った以前の(成功した)呼び出しから要求XMLを構築しています。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ILOService/GetLoanActions</Action>
  </s:Header>
  <s:Body>
    <GetLoanActions xmlns="http://tempuri.org/">
      <request xmlns:d4p1="http://schemas.datacontract.org/2004/07/LOServices.Proxy.Requests" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:AssociationNumber>3</d4p1:AssociationNumber>
        <d4p1:IgnoreWarnings>false</d4p1:IgnoreWarnings>
      </request>
    </GetLoanActions>
  </s:Body>
</s:Envelope>

したがって、私が使用している実際のJavaScriptは、次のように構成されています。

        function callWs() {
            var theRequest = " \
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
  <s:Header> \
    <Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/ILOService/GetLoanActions</Action> \
  </s:Header> \
  <s:Body> \
    <GetLoanActions xmlns=\"http://tempuri.org/\"> \
      <request xmlns:d4p1=\"http://schemas.datacontract.org/2004/07/LOServices.Proxy.Requests\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"> \
        <d4p1:AssociationNumber>3</d4p1:AssociationNumber> \
        <d4p1:IgnoreWarnings>false</d4p1:IgnoreWarnings> \
      </request> \
    </GetLoanActions> \
  </s:Body> \
</s:Envelope>";

            $.ajax({
                type: "POST",
                url: "http://localhost/LOServices/Services/LOService.svc/basic",
                data: theRequest,
                timeout: 10000,
                contentType: "text/xml",
                dataType: "xml",
                async: false
            });
        }

ただし、この方法で実行すると、wcfサービスから「不正な要求」を受け取ることができて残念です。それでもフォローアップの余地はあまりありません。

私は少なくとも3時間この作品を作るのに苦労してきましたので、誰かアイデアがあれば、遠慮なくいくつかの提案をしてください。

ありがとう。

4

1 に答える 1

5

BasicHttpBindingリクエストの場合、HTTPリクエストにSOAPActionヘッダーを設定する必要があります(これにより、メッセージを受信する操作が定義されます)。

$.ajax({
      type: "POST",
      url: "http://localhost/LOServices/Services/LOService.svc/basic",
      data: theRequest,
      timeout: 10000,
      contentType: "text/xml",
      dataType: "xml",
      async: false,
      headers: { "SOAPAction": "http://tempuri.org/Contract/Operation" }
    });

このheadersオプションはjQuery1.5の新機能であるため、古いオプションを使用している場合は、そのためのbeforeSend関数を使用する必要があります。

また、WCFのトレースを有効にすることで、「不正な要求」や「内部サーバーエラー」などのエラーについて、将来さらに多くの情報を取得できるようになります。トレースには、問題に関するより詳細な情報が含まれます。

于 2011-07-15T20:44:43.273 に答える