I am using custom binding and getting following error :
The Scheme cannot be computed for this binding because this CustomBinding lacks a TransportBindingElement. Every binding must have at least one binding element that derives from 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:
<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 ). There is also a project on github with good working sample. 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.
One more step by step example is here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.