我需要以编程方式配置客户端 WCF,因为我的代码适用于 Addin VS 2008。
ADdin VS 2008 的主要 app.config 是:
C:\Archivos de programa\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.Config
我宁愿不要修改这个文件,公司里有很多程序员使用 VS 2008。
而且我无法访问配置,我需要以编程方式配置 WCF 客户端。
我的配置是:
<system.serviceModel>
<extensions>
<bindingElementExtensions>
<add name="customTextMessageEncoding"
type="Microsoft.ServiceModel.Samples.CustomTextMessageEncodingElement,CalidadCodigo.IntegracionEasyVista.CustomTextEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
<bindings>
<basicHttpBinding>
<binding name="WebServiceBinding" 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>
<customBinding>
<binding name="ISO8859Binding">
<customTextMessageEncoding messageVersion="Soap11WSAddressing10"
encoding="ISO-8859-1" />
<httpTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://easy/webservice/SmoBridge.php"
binding="customBinding" bindingConfiguration="ISO8859Binding"
contract="ServiceEasyVista.WebServicePortType" name="EasyVistaSvcEndPoint" />
</client>
</system.serviceModel>
我怎样才能以编程方式做到这一点?
我想这样做,但要使用 CustomBinding 和 BindingExtensions:
//var binding = new System.ServiceModel.BasicHttpBinding();
var binding = new System.ServiceModel.Channels.CustomBinding();
ConfigureBinding(binding);
var endpoint = new System.ServiceModel.EndpointAddress(EndPointActivo);
using (var gdc = new GestorDesplieguesClient(binding, endpoint))
{
eeBres = gdc.EsEntornoBRS(eeBreq);
return eeBres.Resultado;
}