2009-04-08 3 views
2

コードに変換する必要があるapp.configセクションは次のとおりです。私はいくつかの例を見てきましたが、まだそれを動作させることはできません。誰でも助けてくれますか?このapp.config xmlをコードに変換しますか? (WCF)

<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> 

私のユースケースは、私は他のnon-.netのアプリケーションで使用されるDLLを書いていますし、今後私はApp.configファイルを置くのには良い場所を持っていないということです。

ありがとうございます!

+0

は、たぶん、あなたがこれまで持っているものを示し、そして人々は問題 –

+0

@Sunny指摘しようとすることができます含めるためのおかげでXML、それを作るためのトリックは何ですか? – Eyvind

答えて

2

あなたはこのようなもの(それはかなり標準basicHttpBindingのように見えます)使用できます。これは、限り、あなたは契約(「MyService.MyServiceInterface」)を含むDLLを持っているように動作します

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(); 

利用可能にし、次のことができますそれをあなたのクライアントで参照してください。

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

マルク・

PS://アドレス - コード内のいくつかの追加のセキュリティ設定が必要な場合があります。申し訳ありませんが、私はちょうどあなたがhttpsを使用気づきました。

1

marc_sさん、ありがとうございます、あなたは正しい方向に私を導いてくれました!興味がある人々のために

は、ここでは同様にSSLで動作させるためのコードは次のとおりです。

 BasicHttpBinding binding = new BasicHttpBinding(); 
     binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; 
     Uri endpointAddress = new Uri("https://server.com/Service.asmx"); 

     ChannelFactory<MyService.MyServiceInterface> factory = new ChannelFactory<MyService.MyServiceInterface>(binding, endpointAddress.ToString()); 
     factory.Credentials.UserName.UserName = "username"; 
     factory.Credentials.UserName.Password = "password"; 

     MyService.MyServiceInterface client = factory.CreateChannel(); 

     // make use of client to call web service here... 
+0

よかった、うれしかったよ! (私は今WCF試験のために学んでいますので、このようなものは私の心に新鮮でなければなりません:-) –