以编程方式使用 CustomBinding 和 BindingExtensions 配置 WCF

发布于 2024-10-06 19:05:43 字数 3178 浏览 7 评论 0原文

我需要以编程方式配置客户端 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文