【问题标题】:Error on adding Service Reference due to an amount of service operations由于大量服务操作,添加服务参考时出错
【发布时间】:2012-07-31 11:52:18
【问题描述】:

我的服务合同包含足够数量的操作(约 40 次操作)。当我尝试从我的客户端项目(甚至是 WCF Test Client)添加服务参考时,我收到了一个错误:

错误:无法从 net.tcp://localhost:12345/DataProvider/mex 如果这是 Windows (R) 请访问您有权访问的通信基础服务 检查您是否已在指定位置启用元数据发布 地址。有关启用元数据发布的帮助,请参阅 MSDN 文档位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:net.tcp://localhost:12345/DataProvider/mex 元数据 包含无法解析的引用: 'net.tcp://localhost:12345/DataProvider/mex'。有一个错误 XML 文档。 “类型”属性的值无效 - 'q2:PersonFilter' 是 'type' 属性的无效值。

从这里开始的奇怪行为:当什么都不做,但删除一个服务操作时,一切都很顺利 - 添加服务引用效果非常好。当然,我并没有尝试删除这 ~40 种方法中的所有方法,但我尝试了 ~5 种方法。 另一件重要的事情 - 我没有删除使用PersonFilter(错误消息中显示的类型)运行的方法。

我不知道如何解决这个问题。如果需要更多信息,请告诉我。

更新 #1

所以,我刚刚尝试设置 mex 自定义绑定以增加默认配额:

  <customBinding>
    <binding name="mexBinding">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                      maxNameTableCharCount="2147483647" />
      </binaryMessageEncoding>
      <tcpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647" 
                    maxBufferSize="2147483647" />
    </binding>
  </customBinding>

  <service name="MyNamespace.DataService" behaviorConfiguration="myServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:12345/DataProvider/" />
      </baseAddresses>
    </host>

    <endpoint binding="netTcpBinding" bindingConfiguration="NetTcpBinding"
              contract="MyNamespace.IDataService" />
    <endpoint address="mex" binding="customBinding" bindingConfiguration="mexBinding"
              name="tcp" contract="IMetadataExchange" />
  </service>

但这无济于事——同样的错误仍在发生。

更新 #2

使用 ServiceModel Metadata Utility Tool (Svcutil.exe) 我尝试从以下 3 个来源获取元数据:

  1. HTTP 主机
  2. TCP 主机
  3. 直接组装

至于来源 1. 和 3. - 一切正常。我能够获取元数据并生成客户端代码,但是当我通过 TCP 主机调用 svcutil 时,我得到了:

Microsoft (R) 服务模型元数据工具 [Microsoft (R) Windows (R) 通信基础,版本 4.0.30319.1] 版权所有 (c) Microsoft 公司。保留所有权利。

尝试从以下位置下载元数据 'net.tcp://localhost:12345/DataProvider/mex' 使用 WS-Metadata Exchange。 此网址不支持 DISCO。

Microsoft (R) 服务模型元数据工具 [Microsoft (R) Windows (R) 通信基础,版本 4.0.30319.1] 版权所有 (c) Microsoft 公司。保留所有权利。

错误:无法从 net.tcp://localhost:12345/DataProvider/mex

如果这是您使用的 Windows (R) Communication Foundation 服务 有访问权限,请检查您是否已在指定地址启用元数据发布。如需帮助启用元数据发布, 请参阅 MSDN 文档 http://go.microsoft.com/fwlink/?LinkId=65455.

WS-元数据交换错误 URI:net.tcp://localhost:12345/DataProvider/mex

Metadata contains a reference that cannot be resolved: 'net.tcp://12345/DataProvider/Management/mex'.

There is an error in the XML document.

The value for the 'type' attribute is invalid - 'q2:PersonFilter' is an invalid value for the 'type' attribute.

如果您需要更多帮助,请输入“svcutil /?”

我仍然不知道我的 wcf 服务或其配置出了什么问题。

【问题讨论】:

  • 你能把一个工作的元数据和一个不工作的元数据一起发布吗?
  • @Frobzig 好吧,老实说,我不能......我可以直接从程序集中获取元数据,我可以从 http 主机获取它,但不能从tcp 主机.. 我将在几分钟后在我的问题中提供更多详细信息。
  • @Frobzig 所以,我已经更新了我的问题
  • 我也遇到过类似的问题。我不记得细节,但问题是我的服务太大了。我必须编辑 Visual Studio 配置,在其中添加了允许的内存以进行代理生成,问题就解决了。
  • @Bogdan0x400 如果需要更新 Visual Studio 配置,很遗憾。我为其他开发人员提供 wcf 服务,我不能要求完成此 VS 配置更改。

标签: c# .net wcf


【解决方案1】:

首先让服务使用基本的 http 绑定,然后再将其更改为 net tcp,通常会更容易。

除了定义 mex 端点之外,您还需要启用元数据交换:

<behaviors> 
  <serviceBehaviors> 
    <behavior name="myServiceBehavior"> 
        <serviceDebug includeExceptionDetailInFaults="True" /> 
        <serviceMetadata /> 
    </behavior> 
   </serviceBehaviors> 
 </behaviors> 

没有&lt;serviceMetadata /&gt; 元素,mex 端点将无法工作。

【讨论】:

    【解决方案2】:

    好吧,我很久以前就找到了解决方案,但我完全忘记发布答案了。

    所以,我对 Visual Studio 配置文件 devenv.exe.config 进行了一些更改。我刚刚添加了system.serviceModel 部分,如下所示:

    <system.serviceModel>
        <client>
            <endpoint binding="netTcpBinding" bindingConfiguration="GenericBinding" contract="IMetadataExchange" name="net.tcp" />
        </client>
        <bindings>
            <netTcpBinding>
                <binding name="GenericBinding"
                         maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
                         maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647"
                                  maxStringContentLength="2147483647"
                                  maxArrayLength="2147483647"
                                  maxBytesPerRead="2147483647"
                                  maxNameTableCharCount="2147483647" />
                    <security mode="None" />
                </binding>
            </netTcpBinding>
        </bindings>
    </system.serviceModel>
    

    现在一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      相关资源
      最近更新 更多