5

私はWSEとWCFの両方に不慣れで、WCFを使用してWebサービスを利用しようとしていますが、ドキュメントの例はすべてVS2005+WSE用です。このWebサービスはWS-Security1.0を使用します。Visual Studioを介してサービス参照を追加しましたが、WCFで以下のコードと同等の方法を実行する方法がわかりません。

// 1. Initialize the web service proxy
PartnerAPIWse integrationFramework = new PartnerAPIWse();

// 2. Set the username/password. This is using the Username token of WS-Security 1.0
UsernameTokenProvider utp = new UsernameTokenProvider("username", "password");
integrationFramework.SetClientCredential<UsernameToken>(utp.GetToken());

// 3. Declare the policy
Policy policy = new Policy(new UsernameOverTransportAssertion());
integrationFramework.SetPolicy(policy);
4

1 に答える 1

8

実験をして1日を過ごした後、私はこのコードを変換する方法を見つけました。重要なのは、VS2008が正しく作成するWCFプロキシにバインディングを設定することでした。

  1. WSDLを指すサービス参照を追加します
  2. App.config / Web.configを開き、system.serviceModelセクションを見つけます。デフォルトのsoapbindingのセキュリティモードをTransportWithMessageCredentialに変更します。変更後のファイルは次のようになります。

            <basicHttpBinding>
            <binding name="SoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    
  3. 上記のサンプルコードを次のように変更します

    Dim integrationFramework As New SoapClient()
    integrationFramework.ClientCredentials.UserName.UserName = "username"
    integrationFramework.ClientCredentials.UserName.Password = "password"
    

TransportWithMessageCredentialは、WSE3.0のUsernameOverTransportAssertionポリシーと同等です。

于 2009-04-23T14:25:28.067 に答える