C# WCF - ConfigurationErrorsException
I have created (using an online example) a custom binding and I'm trying to use it. Unfortunately I need to register the new binding.
Here is my app.config file.
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="WCFServiceHost.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<appSettings>
<add key="ThreadPoolSize" value="10"/>
<add key="ChunkLength" value="60"/>
<add key="ClientSettingsProvider.ServiceUri" value=""/>
</appSettings>
<system.web>
<compilation debug="tru开发者_如何学Ce">
<assemblies>
<add assembly="UdpBinding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
</providers>
</roleManager>
</system.web>
<system.serviceModel>
<client>
<metadata>
<wsdlImporters>
<extension type="UdpTransportBinding.UdpTransportElement, UdpTransportBinding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</wsdlImporters>
<policyImporters>
<extension type="UdpTransportBinding.UdpBindingCollectionElement, UdpTransportBinding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</policyImporters>
</metadata>
</client>
<services>
<service name="TransportService.TransportProtocol" behaviorConfiguration="MyBehavior">
<endpoint name="NetTcpEndPoint" address="" binding="netTcpBinding" contract="TransportService.ITransportProtocol">
</endpoint>
<endpoint name="BasicHttpBinding" address="" binding="basicHttpBinding" contract="TransportService.ITransportProtocol">
</endpoint>
<endpoint name="NetUdpEndpoint" address="" binding="udpTransportBinding" bindingConfiguration="config" contract="TransportService.ITransportProtocol">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<bindingElementExtensions>
<add name="udpTransport" type="UdpTransportBinding.UdpTransportElement, UdpTransportBinding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingElementExtensions>
<bindingExtensions>
<add name="udpTransportBinding" type="UdpTransportBinding.UdpBindingCollectionElement, UdpTransportBinding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingExtensions>
</extensions>
<bindings>
<udpTransportBinding>
<binding name="config"/>
<udpTransport/>
</udpTransportBinding>
</bindings>
I've an app.config
like this, but when I ran the old algorithm I got this error:
Configuration binding extension system.serviceModel/bindings/udpTransportBinding could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
Can someone help me to solve this problem?
First, are you absolutely sure this is the proper type/assembly information for your class?
UdpTransportBinding.UdpBindingCollectionElement, UdpTransportBinding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
One way you can find out exactly where WCF is having a problem is to turn on handling of first chance exceptions and seeing what kind of WCF is getting internally before it reports its nice error. To do this you can disabled "Just My Code" in settings and check off handling of exceptions in the Debug->Exceptions menu.
Second, this config can't be right:
<udpTransportBinding>
<binding name="config"/>
<!-- this can't be outside the binding -->
<udpTransport/>
</udpTransportBinding>
Are you sure that's exactly what you have? Also why are you creating a binding extension explicitly for udpTransportBinding, but then explicitly declaring that is uses udpTransport inside of it? The whole point of having a predefined binding is that it would automatically select that transport by default. You would really only want users to specify the udpTransport binding element if they defined a custom binding.
精彩评论