3

WCF で WS-Security 対応サービスを利用しようとしています。認証は UsernameToken を使用して機能します。私は WCF Web サービス クライアントについてあまり詳しくありませんが、以下の構成は通常の HTTP 通信で機能すると思います。私は(ほとんど)このガイドを使用して構成しました。主な違いは、コマンド プロンプトの代わりに VS2010 の「サービス参照の追加」UI を使用したことです。

私の問題は、HTTPS 経由でこれを行う必要があることです。<security mode="Message">app.config で使用すると、soap エンベロープに必要な WS-Security ヘッダーが含まれていると思います。ロギングを機能させることができないため、はっきりとは言えません。ただし、次のエラーが表示されますThe provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via

以下は、私の app.config ファイルの内容とクライアント コードのサンプルです。

<configuration>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Omitted" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Message">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" negotiateServiceCredential="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://omitted.com/service" binding="wsHttpBinding" bindingConfiguration="Omitted" contract="Omitted.Omitted" name="Omitted" />
</client>
  </system.serviceModel>

var service = new OmittedClient();
service.ClientCredentials.UserName.UserName = "username";
service.ClientCredentials.UserName.Password = "password";    
var response = service.DoSomething(new DoSomethingRequest());
4

1 に答える 1

1

500 - Internal Server error に感謝します。私が取った手順は次のとおりです。

  1. Visual Studio/WCF を使用してプロキシを生成します。
  2. セキュリティ モードを TransportWithmessageCredential に変更します。
  3. 次のコードを使用して、ユーザー名/パスワードを指定します。
    var クライアント = 新しい WebServiceClient();
    client.ClientCredentials.UserName.UserName = "ユーザー名";
    client.ClientCredentials.UserName.Password = "パスワード";
  1. 応答が返されても、処理中に WCF がエラーを出す場合は、応答にタイムスタンプが含まれていない可能性があります。その場合は、これを修正してみてください。
    // WCF がタイムスタンプの欠落を訴える (http://www.west-wind.com/weblog/posts/2007/Dec/09/Tracing-WCF-Messages)
    var 要素 = service.Endpoint.Binding.CreateBindingElements();
    Elements.Find().IncludeTimestamp = false;
    service.Endpoint.Binding = 新しい CustomBinding(要素);
于 2012-06-19T16:43:22.580 に答える