VS2012 WCF REST服务-错误:无法获取元数据 [英] VS2012 WCF REST Service - Error: Cannot obtain metadata

查看:118
本文介绍了VS2012 WCF REST服务-错误:无法获取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了WCF REST Web服务(WCF服务应用程序),当我使用Visual Studio 2012进行调试时,它将启动WCF Test Client应用程序并尝试添加我的Web服务。我收到以下错误:

I have built a WCF REST web service (WCF Service Application) and when I debug with Visual Studio 2012, it will spin up the WCF Test Client app and try to add my web service. I am getting the following error:

Error: Cannot obtain Metadata from http://localhost:50925/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:50925/Service1.svc    Metadata contains a reference that cannot be resolved: 'http://localhost:50925/Service1.svc'.    Content Type application/soap+xml; charset=utf-8 was not supported by service 

支持。我访问了上面链接的MSDN文档,我相信我已经正确设置了web.config。

I have visited the MSDN document linked above and I believe I have set up my web.config correctly.

Web.config:

Web.config:

<?xml version="1.0"?>
<configuration>
<system.web>
 <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>  
<system.serviceModel>   
<services>
  <service name="Service1" behaviorConfiguration="Service1Behavior">       
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex">     </endpoint>
  </service>
</services>  
<behaviors>
  <serviceBehaviors>
    <behavior name="Service1Behavior">
      <serviceMetadata httpGetEnabled="true"/>     
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>   
</system.webServer>
</configuration>

我仍然继续收到相同的错误消息。我是WCF / VS 2012和.Net 4.0的新手,但我精通VS2008 .Net 2.0。

I still continue to receive the same error message. I am new to WCF / VS 2012 and .Net 4.0, but I am fluent in VS2008 .Net 2.0.

推荐答案

WCF REST服务不会公开元数据,这就是您收到该消息的原因(请参阅此博客文章)。如果您使用的是WCF测试客户端,则它是在与SOAP服务(端点)通信,而不是与REST服务通信。

WCF REST services do not expose metadata, which is why you were getting that message (see more details in this blog post). If you're using the WCF Test Client, it's talking to a SOAP service (endpoint), not a REST one.

如果要启用RESTful端点,则可以在配置中定义service元素,并在其中定义一个使用 webHttpBinding 的终结点,该终结点还需要一个 behaviorConfiguration 指向具有< webHttp /> 行为的端点行为。

If you want to enable a RESTful endpoint, you can define the service element in configuration and define an endpoint inside of it which uses the webHttpBinding, and the endpoint also needs a behaviorConfiguration pointing to an endpoint behavior with the <webHttp/> behavior.

这篇关于VS2012 WCF REST服务-错误:无法获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆