WCF - 错误:无法获取元数据 [英] WCF - Error: Cannot obtain Metadata

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

问题描述

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

When I try to run my application from the WCF Test Client I receive the following error:

错误:无法从 http://localhost:53867/MyAPI.svc 获取元数据如果是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布.
有关启用元数据发布的帮助,请参阅位于 http://go 的 MSDN 文档.microsoft.com/fwlink/?LinkId=65455.WS-Metadata 交换错误
URI:http://localhost:53867/MyAPI.svc
元数据包含无法解析的引用: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 服务发现信息.

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:

Here is some of my 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.

推荐答案

   <behavior name="MyServiceBehavior"> 

来自

   <binding name="MembershipBinding">

并添加 serviceMetadata 元素

and add serviceMetadata element

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

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

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

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