Tengo un servicio WCF que funciona bien si creo el servicio sin especificar ningún enlace o punto final (lo lee de los valores generados en el App.config cuando registré el WCF a través de Visual Studio).WCF: ¿Cómo puedo recrear de forma programática estos valores de App.config?
Tengo un método simple que devuelve la referencia de servicio:
return new SmsServiceReference.SmsEngineServiceClient();
Esto funciona bien (porque los valores se leen de la configuración). Sin embargo, me gustaría tener algunos de estos valores en una base de datos (el URI por ejemplo) y me gustaría hacer algo como esto:
Binding binding = new BasicHttpBinding();
EndpointAddress endpointAddress = new EndpointAddress("my.uri.com/service.svc");
return new SmsServiceReference.SmsEngineServiceClient(binding,endpointAddress);
Esto no funciona. Lanza una excepción cuando trato de usar la referencia de servicio.
Sospecho que esto se debe a que mi App.config tiene más información que las dos líneas no están proporcionando (obviamente). La pregunta es, ¿cómo puedo replicar los siguientes valores de App.Config programáticamente?
Aquí está el fragmento de mi App.Config: (el URI ha sido alterado para proteger al inocente).
<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>
Esto hizo el truco. Gracias. –