【问题标题】:C# WCF - ConfigurationErrorsExceptionC# WCF - 配置错误异常
【发布时间】:2011-05-16 21:26:03
【问题描述】:

我已经创建(使用在线示例)一个自定义绑定,我正在尝试使用它。不幸的是,我需要注册新的绑定。

这是我的 app.config 文件。

<?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="true">
      <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>

我有一个这样的app.config,但是当我运行旧算法时,我得到了这个错误:

配置绑定扩展 system.serviceModel/bindings/udpTransportBinding 找不到。验证这 绑定扩展是正确的 注册于 system.serviceModel/extensions/bindingExtensions 并且拼写正确。

谁能帮我解决这个问题?

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    首先,您确定这是适合您班级的类型/程序集信息吗?

    UdpTransportBinding.UdpBindingCollectionElement, UdpTransportBinding,版本=4.0.0.0, 文化=中性, PublicKeyToken=31bf3856ad364e35

    您可以准确找出 WCF 在哪里出现问题的一种方法是打开对第一次机会异常的处理,并在 WCF 报告其良好错误之前查看内部正在获取哪种类型的 WCF。为此,您可以在设置中禁用“仅我的代码”,并在 Debug->Exceptions 菜单中检查异常处理。

    第二,这个配置不对:

    <udpTransportBinding>    
        <binding name="config"/>
        <!-- this can't be outside the binding -->    
        <udpTransport/> 
    </udpTransportBinding>
    

    你确定这正是你所拥有的吗?另外,为什么要为 udpTransportBinding 显式创建绑定扩展,然后显式声明它在其中使用 udpTransport?具有预定义绑定的全部意义在于它会默认自动选择该传输。如果用户定义了自定义绑定,您实际上只希望用户指定 udpTransport 绑定元素。

    【讨论】:

    • 一开始我没有这部分,错误是一样的。我根据网上的建议添加了它。
    • 好吧,在绑定中指定传输是多余的,理论上存在为您配置传输的绑定。让我们坚持你得到的例外,你确定绑定集合元素是正确的程序集/版本/publickeytoken吗?顺便说一句,您实际上不需要为这些特定扩展使用完整版本规范程序集名称格式,您可以只执行“UdpTransportBinding.UdpBindingCollectionElement,UdpTransportBinding”。只有行为扩展需要完整版本规范(很遗憾)。
    • 无事可做,删除这些信息也没什么变化。
    • 您将不得不在第一次机会异常打开的情况下进行调试,以查看 WCF 在幕后遇到了什么问题。我看不出你声称做的事情有什么问题,所以应该没有理由不工作。
    猜你喜欢
    • 1970-01-01
    • 2010-09-10
    • 2022-07-16
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 2011-04-07
    相关资源
    最近更新 更多