【问题标题】:Cannot get Metadata with WCF无法使用 WCF 获取元数据
【发布时间】:2012-12-03 03:44:04
【问题描述】:

我正在尝试设置一个返回 JSON 对象的 Web 服务,并且我正在关注这个 tutorial 但是当我尝试运行它时,我收到了这个错误

错误:无法从http://localhost:10995/Service1.svc 获取元数据 如果这是您使用的 Windows (R) Communication Foundation 服务 有访问权限,请检查您是否已在以下位置启用元数据发布 指定的地址。如需帮助启用元数据发布,请 请参阅 MSDN 文档 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:http://localhost:10995/Service1.svc 元数据包含 无法解析的引用: '本地主机:10995/Service1.svc'。远程服务器返回 意外响应:(405) 方法不允许。远程服务器 返回错误:(405)方法不允许。HTTP GET错误URI: http://localhost:10995/Service1.svc下载时出错 http://localhost:10995/Service1.svc。 HTTP 请求失败 状态 404:未找到。

所以我尝试查找这意味着什么,并通过这些链接尝试修复它

WCF - Cannot obtain Metadata

WCF - Error: Cannot obtain Metadata

Error: Cannot obtain Metadata from WCF service

WCF Test Client cannot add service, cannot obtain metadata

但他们都没有解决问题。这是我第一次尝试做任何类型的网络服务,而且我今天开始研究,所以显然我对这一切都是新手。

这个错误是什么意思,我该如何修复它以便我可以测试它?

<system.serviceModel>
<services>
  <service name="WcfService4.Service1" behaviorConfiguration="WcfService4.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="../Service1.svc"
      binding="webHttpBinding"
      contract="WcfService4.IService1"
      behaviorConfiguration="webBehaviour" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="WcfService4.Service1Behavior">
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webBehaviour">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

【问题讨论】:

  • 正确检查端点地址、行为配置和合约名称。
  • 所以没有赞成的答案或绿色勾号..知道什么可以解决这个问题吗?

标签: c# wcf web-services


【解决方案1】:

这不仅仅是一个错字吗?

contract="WcfService4e.IService1" 

应该是这样的

contract="WcfService4.IService1"

【讨论】:

    【解决方案2】:

    试试这个

    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
    

    【讨论】:

      【解决方案3】:

      将命名空间名称与您的服务名称和合同名称一起使用...参见 下面的代码sn-p:

      <service name="WcfService3.Service1"
       behaviorConfiguration="ServiceBehavior">
      >         
      <endpoint address="../Service1.svc" binding="wsHttpBinding" contract="WcfService3.IService1">
      

      其中 "WcfService3" 是名称空间。

      【讨论】:

        猜你喜欢
        • 2012-05-08
        • 1970-01-01
        • 2012-04-28
        • 2023-03-25
        • 1970-01-01
        • 2016-04-03
        • 2011-08-28
        • 2011-04-01
        • 1970-01-01
        相关资源
        最近更新 更多