WCF - 错误:无法获取元数据

时间:2012-04-17 14:06:49

标签: c# wcf wcf-security

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

  

错误:无法从http://localhost:53867/MyAPI.svc获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。
  有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange错误的MSDN文档   URI:http://localhost:53867/MyAPI.svc
  元数据包含无法解析的引用:'http:// localhost:53867 / MyAPI.svc'。
  内容类型application / soap + xml;服务http://localhost:53867/MyAPI.svc不支持charset = utf-8   客户端和服务绑定可能不匹配   远程服务器返回错误:(415)不支持的媒体类型.HTTP GET错误
  URI:http://localhost:53867/MyAPI.svc
  HTML文档不包含Web服务发现信息。

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

我不知道是什么原因引起的?我的成员资格提供程序位于该位置,并且具有正确的命名空间。

1 个答案:

答案 0 :(得分:6)

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

   <binding name="MembershipBinding">

并添加serviceMetadata元素

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

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