如果我创建服务而不指定任何绑定或端点(当我通过 Visual Studio 注册 WCF 时,它从 App.config 中生成的值中读取它),我有一个工作正常的 WCF 服务。
我有一个返回服务引用的简单方法:
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 有更多信息,而这两行没有提供(显然)。问题是,如何以编程方式复制以下 App.Config 值?
这是我的 App.Config 的片段:(URI 已被更改以保护无辜者)。
<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>