我有一个WCF服务,如果我创建服务时不指定任何绑定或终结点(通过Visual Studio注册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 提供了更多信息,而上面那两行代码并没有提供(显然)。问题是,我该如何在程序中复制以下 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>