バインディングやエンドポイント(Visual Studio経由でWCFを登録したときにApp.configの生成された値から読み込みます)を指定せずにサービスを作成すると、正常に動作するWCFサービスがあります。WCF:これらのApp.config値をプログラムで再作成するにはどうすればよいですか?
私は、サービス参照を返す簡単な方法があります(値は設定から読み込まれるため)
return new SmsServiceReference.SmsEngineServiceClient();
これはうまく動作します。しかし、私は、データベース(例えばURI)で、これらの値のいくつかを持っているしたいと、このような何かをしたいと思います:これは動作しません
Binding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("my.uri.com/service.svc");
return new SmsServiceReference.SmsEngineServiceClient(binding,endpointAddress);
。サービス参照を使用しようとすると例外がスローされます。
これは、私のApp.configには2つの行が提供されていないことが明らかです(明らかに)。問題は、次のApp.Config値をプログラムで複製するにはどうすればいいですか?
私のApp.Configの断片です:(URIはinocentを保護するために変更されています)。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISmsEngineService" 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="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.myuri.com/Services/Services.svc/basic"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISmsEngineService"
contract="SmsServiceReference.ISmsEngineService" name="BasicHttpBinding_ISmsEngineService" />
</client>
これはトリックでした。ありがとう。 –