c# - WCF - 错误 : Cannot obtain Metadata

标签 c# wcf wcf-security

当我尝试从 WCF 测试客户端运行我的应用程序时,我收到以下错误:

Error: Cannot obtain Metadata from http://localhost:53867/MyAPI.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: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.

这是我的一些 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>

我不知道是什么原因造成的?我的成员(member)提供者在那个位置,它有正确的命名空间。

最佳答案

中删除名称属性
   <behavior name="MyServiceBehavior"> 

   <binding name="MembershipBinding">

并添加 serviceMetadata 元素

    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="True"/>
                <serviceCredentials>
                <userNameAuthentication
                    userNamePasswordValidationMode="MembershipProvider"
                    membershipProviderName="CustomMembershipProvider" />
                </serviceCredentials>

            </behavior>
        </serviceBehaviors>
    </behaviors>

关于c# - WCF - 错误 : Cannot obtain Metadata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10192824/

相关文章:

c# - 在调试中关闭 WCF 应用程序启动

c# - WCF 错误 - 安全处理器无法在消息中找到安全 header

wcf - ServiceSecurityContext.WindowsIdentity 的用途?

c# - 在客户端和服务端应用异步等待的区别

c# - 如何在另一个项目中分离 Entity Framework

c# - 事件在错误的线程中?

c# - wcf 联合安全 token 是 session token 还是可重用的?

c# - IEnumerable<XElement> 和 foreach

C# WCF - 查找被调用的端点的名称

WCF 服务设计示例