Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF自定义绑定配置_Wcf_Web Services - Fatal编程技术网

WCF自定义绑定配置

WCF自定义绑定配置,wcf,web-services,Wcf,Web Services,我已经编写了一个从CustomBinding继承的自定义绑定类。 我的自定义类重写BuildChannelFactory方法,并使用自定义ChannelFactory创建自定义通道 在WCF客户端中使用自定义绑定类时遇到困难。 如果在代码中配置自定义绑定类,则可以使用该类: Binding myCustomBinding = new MyCustomBinding(); ChannelFactory<ICustomerService> factory = new Chann

我已经编写了一个从CustomBinding继承的自定义绑定类。 我的自定义类重写BuildChannelFactory方法,并使用自定义ChannelFactory创建自定义通道

在WCF客户端中使用自定义绑定类时遇到困难。 如果在代码中配置自定义绑定类,则可以使用该类:

Binding myCustomBinding = new MyCustomBinding();

ChannelFactory<ICustomerService> factory = 
   new ChannelFactory<ICustomerService>(myCustomBinding, 
        new EndpointAddress("http://localhost:8001/MyWcfServices/CustomerService/"));

ICustomerService serviceProxy = factory.CreateChannel();
serviceProxy.GetData(5);
Binding myCustomBinding=新建myCustomBinding();
渠道工厂=
新渠道工厂(myCustomBinding,
新端点地址(“http://localhost:8001/MyWcfServices/CustomerService/"));
ICCustomerService serviceProxy=factory.CreateChannel();
serviceProxy.GetData(5);
我的问题是我不知道如何在App.config文件中配置它。
它是customBinding元素还是bindingExtension元素?是其他原因吗?

在代码中创建自定义绑定时,是否同时实现了“YourBindingElement”(源自StandardBindingElement)和“YourBindingCollectionElement”(源自StandardBindingCollectionElement)

如果是-使用它来配置自定义绑定,就像它是任何其他绑定一样

第一步是在的extensions部分的app.config或web.config文件中注册绑定


其中包括一些样本,我从这些样本中基本上学到了足够的知识来解决这个问题:-)

创建自定义绑定有一个非常好的方法—本系列的第2部分,但第1部分不公开:-(

下面是一个示例自定义代码绑定,您可以下载完整的源代码:


Marc

如果要通过配置使用此自定义绑定,必须扩展BindingCollectionElement抽象基并在web.config中定义bindingExtensions元素

<extensions>
  <bindingExtensions>
    <add name="yourBindingName" 
       type="YourBinding.YourBindingCollectionElement, YourBindingAssembly" />
  </bindingExtensions>
</extensions>
<bindings>
  <yourBinding>
    <binding name="yourBindingConfig" 
             proxyAddress="...." useDefaultWebProxy="false" />
  </yourBinding>
</bindings>
<client>
  <endpoint
    address="....your url here......"
    binding="yourBinding" 
    bindingConfiguration="yourBindingConfig"
    contract="IYourContract" 
    name="YourClientEndpointName" />
</client>