简体   繁体   English

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

[英]WCF - Error: Cannot obtain Metadata

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.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. 错误:无法从http:// localhost:53867 / MyAPI.svc获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。
For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error 有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS-元数据交换错误
URI: http://localhost:53867/MyAPI.svc URI: http:// localhost:53867 / MyAPI.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:53867/MyAPI.svc'. 元数据包含无法解析的引用:'http:// localhost:53867 / MyAPI.svc'。
Content Type application/soap+xml; 内容类型application / soap + xml; charset=utf-8 was not supported by service http://localhost:53867/MyAPI.svc . 服务http:// localhost:53867 / MyAPI.svc不支持charset = utf-8。
The client and service bindings may be mismatched. 客户端和服务绑定可能不匹配。
The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error 远程服务器返回错误:(415)不支持的媒体类型.HTTP GET错误
URI: http://localhost:53867/MyAPI.svc URI: http:// localhost:53867 / MyAPI.svc
The HTML document does not contain Web service discovery information. 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. 我的成员资格提供程序位于该位置,并且具有正确的命名空间。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM