以编程方式使用 CustomBinding 和 BindingExtensions 配置 WCF
我需要以编程方式配置客户端 WCF,因为我的代码适用于 Addin VS 2008。ADdin
VS 2008 的主要 app.config 是:
C:\Archivos de programa\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.Config
I最好不要修改这个文件,公司里有很多程序员使用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;
}
I need config programatically a client WCF, because my code is for Addin VS 2008.
The main app.config for ADdin VS 2008 is:
C:\Archivos de programa\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.Config
I prefer dont modify this file, in company there are many programmers that uses VS 2008.
And I cannot access to the config, I need configure WCF Client programatically.
My config is:
<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>
How can I do it programatically ??
I would like do like this, but for using CustomBinding and 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论