1

検索して検索しましたが、解決策が見つかりません。これに遭遇するのは比較的一般的なようです... https経由のWCF RESTサービス。サービス参照を追加すると、すべてのプロキシ クラスが正しくなり、サービスで定義されたオブジェクトを作成したり、サービスを呼び出したりすることができます。ただし、プロキシのクライアント クラスを使用して構成済みのクライアントを作成することはできません。バインディング、動作、およびエンドポイントを明示的に作成し、それらをクライアントに追加する必要があります。たとえば、すべての調査に基づいて、私ができるはずのことは次のとおりです。

ServiceClient = new ServiceClient();

そして、離れて走ってください。ただし、私がしなければならないことは次のとおりです。

WebHttpBinding serviceBinding = new WebHttpBinding(WebHttpSecurityMode.Transport);
serviceBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endPointAddress
            = new EndpointAddress(<endpointaddress>);

// Create Service Client 
ServiceClient = new ServiceClient(serviceBinding, endPointAddress);

// Add Web Behavior to the EndPoint
WebHttpBehavior webHttpBehavior = new WebHttpBehavior();
ServiceClient.Endpoint.Behaviors.Add(webHttpBehavior);

// Set up the request to POST with a wrapped request
WebInvokeAttribute postAttribute = new WebInvokeAttribute();
postAttribute.Method = "POST";
postAttribute.BodyStyle = WebMessageBodyStyle.WrappedRequest;
ServiceClient.Endpoint.Contract.Operations.Find(<operationname>).Behaviors.Add(postAttribute);

サービス構成を模倣するには:

<behaviors>
      <endpointBehaviors>
        <behavior name="AspNetAjaxBehaviorXml">
          <webHttp />
        </behavior>
      </endpointBehaviors>
       <serviceBehaviors>
          <behavior name="AuthenticationServicesBehavior">
            <serviceMetadata httpsGetEnabled="true" policyVersion="Policy15" />
            <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
          <behavior name="LoggingServicesBehavior">
             <serviceMetadata httpsGetEnabled="true" policyVersion="Policy15" />
             <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
       </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="True" />
    <bindings>
      <webHttpBinding>
        <binding name="WebSslBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
       <service behaviorConfiguration="AuthenticationServicesBehavior"
          name="AuthenticationServices">
          <endpoint address="authenticate" behaviorConfiguration="AspNetAjaxBehaviorXml"
             binding="webHttpBinding" bindingConfiguration="WebSslBinding"
             name="AuthenticationEndPoint" bindingNamespace="<mynamespace>"
             contract="IService" />
       </service>

「サービス参照の追加」は私にこれを与えています:

<bindings>
   <customBinding>
    <binding name="AuthenticationEndPoint">
     <!--    WsdlImporter encountered unrecognized policy assertions in ServiceDescription 'EchoAppsServices':    -->
     <!--    <wsdl:binding name='AuthenticationEndPoint'>    -->
     <!--        <sp:HttpsToken xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">..</sp:HttpsToken>    -->
     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
      messageVersion="Soap12" writeEncoding="utf-8">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
       maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     </textMessageEncoding>
    </binding>
   </customBinding>
  </bindings>
  <client>
   <endpoint binding="customBinding" bindingConfiguration="AuthenticationEndPoint"
    contract="AuthenticationService"
    name="AuthenticationEndPoint" />
  </client>

すぐに使用できる既定のクライアントを作成できないのは、WsdlImporter の問題に関連していると思います。svcutil を使用すると、同様のエラーが発生します。

Warning: The following Policy Assertions were not Imported:
  XPath://wsdl:definitions[@targetNamespace='<mynamespace>']/wsdl:binding[@na
me='AuthenticationEndPoint']
  Assertions:
    <sp:HttpsToken xmlns:sp='http://schemas.xmlsoap.org/ws/2005/07/securitypolic
y'>..</sp:HttpsToken>

自己署名証明書と関係があると確信していますが、makecert を取得して、IIS をクラッシュさせない CA で機能する証明書を取得できません。

環境詳細:VS2008 XP 64bit .NET 3.5 IIS6

助けてくれてありがとう...

4

3 に答える 3

1

クライアント プロキシ クラスを作成する場合、なぜ webHttpBinding を使用するのでしょうか。なぜ wsHttpBinding を使用しないのですか?

webHttpBinding の要点は、クライアントで HttpWebRequest や Microsoft.Http.HttpClient などの標準の Http ツールキットを使用してサービスにアクセスできるようにすることでした。

于 2010-02-18T04:45:17.210 に答える
1

それが単なるタイプミスかどうかはわかりませんが、コードと構成が一致しません。

あなたのコードで見てください:

serviceBinding.Security.Transport.ClientCredentialType = 
      HttpClientCredentialType.Windows;

しかし、あなたの設定では:

<webHttpBinding>
    <binding name="WebSslBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
</webHttpBinding>

コードでは(統合 Windows 認証) に設定しますが、構成では に設定しHttpClientCredentialTypeます。WindowsNone

Windows も使用するように構成を変更してみてください。

      <security mode="Transport">
        <transport clientCredentialType="Windows" />
      </security>

そしてさらに試みる。

より良い結果が得られない場合: インポート後にクライアント構成を手動で更新しないのはなぜですか? WSDL インポーターにはあちこちで問題が発生することが知られており、ほとんどの場合、頭脳を働かせて手動で構成を適応させるだけで問題を解決できます。基本的に、セクション<endpointBehaviors><bindings>セクションをクライアント側の構成にコピーし、適切なエンドポイントを参照するセクションを定義するだけ<client>です。これでほとんどすべてです。

于 2010-02-18T06:17:58.377 に答える
0

あなたは良い点を指摘しますが、私はこの道を歩み始めて、クライアントまたはサーバーのいずれかから呼び出すことができるRESTfulWebサービスを作成しました。今は両方からそのまま呼び出すことができますが、サーバー側を明示的に構成する必要があります。このアプリケーションは複数のエンドユーザーに展開され、パッチを適用するよりも構成ファイルを変更する方が簡単であるため、これは受け入れられません。複数のエンドポイントを作成できることは知っていますが、サービスごとに1つだけ維持する必要があります。お返事ありがとうございます。

于 2010-02-18T05:16:12.510 に答える