2

コードに変換する必要がある次のapp.configセクションがあります。私はいくつかの例を見てきましたが、それでもそれを完全に機能させることはできません。誰か助けてもらえますか?

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="MyService" 
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00" 
                 receiveTimeout="00:10:00" 
                 sendTimeout="00:01: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>
    </bindings>
    <client>
      <endpoint address="https://server.com/service/MyService.asmx"
      binding="basicHttpBinding" bindingConfiguration="MyService"
      contract="MyService.MyServiceInterface"
      name="MyService" />
    </client>
</system.serviceModel>

私のユースケースは、他の非.netアプリケーションで使用されるdllを作成していることです。これ以降、app.configを配置するのに適した場所がありません。

ありがとう!

4

2 に答える 2

2

次のようなものを使用できます (かなり標準的な basicHttpBinding のように見えます)。

BasicHttpBinding binding = new BasicHttpBinding();
Uri endpointAddress = new Uri("https://server.com/service/MyService.asmx");

ChannelFactory<MyService.MyServiceInterface> factory = new ChannelFactory<MyService.MyServiceInterface>(binding, endpointAddress);

MyService.MyServiceInterface proxy = factory.CreateChannel();

これは、利用可能なコントラクト ("MyService.MyServiceInterface") を含む DLL があり、それをクライアントで参照できる限り機能します。

サービス側でこれが必要な場合は、いくつかの異なるクラスなどを使用する必要がありますが、基本は同じです (バインディングを作成し、1 つ以上のエンドポイント アドレスを作成し、それらをバインドします)。

マルク

PS: 申し訳ありませんが、https:// アドレスを使用していることに今気づきました。これには、コードで追加のセキュリティ構成が必要になる場合があります。

于 2009-04-08T16:17:10.387 に答える