【问题标题】:Problem adding a behaviors element to my WCF client config将行为元素添加到我的 WCF 客户端配置时出现问题
【发布时间】:2011-07-03 23:11:04
【问题描述】:

我正在尝试向我的客户端配置文件添加一个行为元素,以便我可以指定 maxItemsInObjectGraph。

我得到的错误是:元素“system.serviceModel”的子元素“行为”无效。预期的可能元素列表:“绑定、客户端、扩展”。

这是我的配置:

<configuration>

  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_KernService" 
          maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceViewEventBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <client>
      <endpoint address="http://localhost/KernMobile.WCF/KernService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_KernService"
        contract="KernWcfService.KernService" name="BasicHttpBinding_KernService"
        behaviorConfiguration="ServiceViewEventBehavior" />
    </client>

  </system.serviceModel>

</configuration>

它还抱怨端点元素中的 behaviorConfiguration 属性。

有什么想法吗? .Net 4.0 顺便说一句。

编辑:我还应该指出,这是在 WP7 项目中。

【问题讨论】:

  • 我想您所指的错误出现在 Visual Studio 错误列表中。对吗?
  • 我在编辑器中看到一条弯曲的蓝线,当我将鼠标悬停在工具提示中时,错误出现在工具提示中。如果我运行该应用程序,我会在服务客户端构造函数中抛出一个无效操作异常:无法识别的元素“行为”。

标签: .net wcf windows-phone-7 config


【解决方案1】:

Silverlight 4 (WP7) 版本的 system.ServiceModel 中不存在 WCF 行为概念。

您需要在其他地方指定 DataContractSerializer 选项(在另一个配置部分或代码中)

客户端/端点上的行为配置也是如此。

请参考此 MSDN 以获得配置说明: http://msdn.microsoft.com/en-us/library/dd540827(v=vs.95).aspx

【讨论】:

  • 你需要吗?在 Silverlight 中,它默认为 Int.MaxValue
  • 太忙于手动更新它,我错过了这个。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-30
  • 2011-04-06
  • 1970-01-01
  • 2011-05-03
  • 2017-02-21
  • 1970-01-01
  • 2014-10-16
相关资源
最近更新 更多