CallumVass
CallumVass

Reputation: 11456

WCF - Error: Cannot obtain Metadata

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

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.

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.

Upvotes: 5

Views: 35399

Answers (1)

Petar Vučetin
Petar Vučetin

Reputation: 3615

Remove the name attribute from

   <behavior name="MyServiceBehavior"> 

and from

   <binding name="MembershipBinding">

and add serviceMetadata element

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

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

Upvotes: 6

Related Questions