C# WCF - 错误:无法获取元数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10192824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF - Error: Cannot obtain Metadata
提问by CallumVass
When I try to run my application from the WCF Test Client I receive the following error:
当我尝试从 WCF 测试客户端运行我的应用程序时,我收到以下错误:
Error: Cannot obtain Metadata from http://localhost:53867/MyAPI.svcIf 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-MetadataExchange Error
URI: http://localhost:53867/MyAPI.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:53867/MyAPI.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:53867/MyAPI.svc.
The client and service bindings may be mismatched.
The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error
URI: http://localhost:53867/MyAPI.svc
The HTML document does not contain Web service discovery information.
错误:无法从http://localhost:53867/MyAPI.svc获取元数据如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。
有关启用元数据发布的帮助,请参阅 MSDN 文档,网址为http://go.microsoft.com/fwlink/?LinkId=65455.WS-MetadataExchange Error
URI: http://localhost:53867/MyAPI.svc
Metadata contains无法解析的引用:'http://localhost:53867/MyAPI.svc'。
内容类型应用程序/soap+xml;服务http://localhost:53867/MyAPI.svc不支持 charset=utf-8 。
客户端和服务绑定可能不匹配。
远程服务器返回错误:(415) Unsupported Media Type.HTTP GET Error
URI: http://localhost:53867/MyAPI.svc
HTML 文档不包含 Web 服务发现信息。
Here is some of my web.config:
这是我的一些 web.config:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<membership defaultProvider="CustomMembershipProvider">
<providers>
<clear/>
<add name="CustomMembershipProvider" type="Namespace.Models.MyMembershipProvider" />
</providers>
</membership>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MembershipBinding">
<security mode ="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="CustomMembershipProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
I've no idea what could be causing this? My Membership Provider is in that location and it has the correct namespace.
我不知道是什么原因造成的?My Membership Provider 位于该位置,并且具有正确的命名空间。
采纳答案by Petar Vu?etin
Remove the name attribute from
删除 name 属性
<behavior name="MyServiceBehavior">
and from
并从
<binding name="MembershipBinding">
and add serviceMetadata element
并添加 serviceMetadata 元素
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="CustomMembershipProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>

