[英]WCF Custom Binding - The Scheme cannot be computed because this CustomBinding lacks a TransportBindingElement
I am using custom binding and getting following error : 我正在使用自定义绑定并出现以下错误:
The Scheme cannot be computed for this binding because this CustomBinding lacks a TransportBindingElement. 无法为此绑定计算方案,因为此CustomBinding缺少TransportBindingElement。 Every binding must have at least one binding element that derives from TransportBindingElement.
每个绑定必须至少具有一个从TransportBindingElement派生的绑定元素。
My Custom Binding Code as follows 我的自定义绑定代码如下
public class MyCustomBinding : Binding
{
private HttpTransportBindingElement transport;
private BinaryMessageEncodingBindingElement encoding;
public MyCustomBinding()
: base()
{
this.InitializeValue();
}
public override BindingElementCollection CreateBindingElements()
{
BindingElementCollection elements = new BindingElementCollection();
elements.Add(this.encoding);
elements.Add(this.transport);
return elements;
}
public override string Scheme
{
get { return this.transport.Scheme; }
}
private void InitializeValue()
{
this.transport = new HttpTransportBindingElement();
this.encoding = new BinaryMessageEncodingBindingElement();
}
}
public class MyCustomBindingCollectionElement : BindingCollectionElement
{
// type of custom binding class
public override Type BindingType
{
get { return typeof(MyCustomBinding); }
}
// override ConfiguredBindings
public override ReadOnlyCollection<IBindingConfigurationElement> ConfiguredBindings
{
get
{
return new ReadOnlyCollection<IBindingConfigurationElement>(
new List<IBindingConfigurationElement>());
}
}
// return Binding class object
protected override Binding GetDefault()
{
return new MyCustomBinding();
}
public override bool ContainsKey(string name) {
return true;
}
protected override bool TryAdd(string name, Binding binding, Configuration config)
{
return true;
}
}
Web.config code is as follows: Web.config代码如下:
<extensions>
<bindingExtensions>
<!--<add name="ProxyElement" type="ADHA.Model.HttpTransportBindingElementProxy, ADHA"/>-->
<add name="MyCustomBinding" type="ADHA.Model.MyCustomBindingCollectionElement,ADHA,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingExtensions>
</extensions>
<service>
<services>
<endpoint address="" binding="customBinding" bindingConfiguration="MyCustomBinding" contract="ADHA.IADHAService">
</endpoint>
<endpoint address="mex" binding="customBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<customBinding>
<binding name="MyCustomBinding">
<binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
maxSessionSize="2048">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binaryMessageEncoding>
<textMessageEncoding
messageVersion="Soap11WSAddressingAugust2004"/>
<httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true"/>
</binding>
</customBinding>
</bindings>
Someone please tell me whats wrong with my code? 有人告诉我我的代码有什么问题吗?
See an example here ( http://webservices20.blogspot.de/2008/11/introducing-wcf-clearusernamebinding.html ). 在此处查看示例( http://webservices20.blogspot.de/2008/11/introducing-wcf-clearusernamebinding.html )。 There is also a project on github with good working sample.
github上还有一个具有良好工作示例的项目 。 You should refer your new type with the new name, defined in extension description.
您应该使用扩展名描述中定义的新名称来引用新类型。 Like that:
像那样:
<extensions>
<bindingExtensions>
<add name="myCustomBinding" type="ADHA.Model.MyCustomBindingCollectionElement, ADHA,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bindingExtensions>
</extensions>
<bindings>
<myCustomBinding>
<binding name="myCustomBindingConfig">
<binaryMessageEncoding />
<httpsTransport />
</binding>
</myCustomBinding>
</bindings>
<services>
<service>
<endpoint address="" binding="customBinding"
bindingConfiguration="myCustomBindingConfig"
contract="ADHA.IADHAService">
</endpoint>
<endpoint address="mex" binding="customBinding" contract="IMetadataExchange" />
</service>
</services>
For that you will have to create a Custom BindingElement with the Configuration.StandardBindingElement and a custom BindingCollectionElement with the Configuration.StandardBindingCollectionElement. 为此,您将必须使用Configuration.StandardBindingElement创建一个自定义BindingElement并使用Configuration.StandardBindingCollectionElement创建一个自定义BindingCollectionElement。
One more step by step example is here. 这里还有一个逐步的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.