John
John

Reputation: 127

WCF service metadata error

I'm trying to develop an WCF service but I got several errors one by one WCFTestClient is pooping out and I'm trying solving them all day long looking into several tutorials and reading posts here, but this I can't figure out why it's happening, what I'm doing wrong and how can I solve it. But first of all, environment, I'm in development process in visual studio 2013, debugging, nowhere in IIS or somewhere else nothing is hosted. By now it looks something like this:
WCF service project
Models: EntityFramework model, nothing big just one table for experiments which is coming from my local DB which is on development PC.
WebService: WCF web service which I'm trying to develop all day long without success by now. In IPersonService class code is something like this:

[ServiceContract]
public interface IPersonService
{
    [OperationContract]
    List<tblUsers> GetPersons();
}

In PersonService.svc code is something like this:

public class PersonService : IPersonService
{
    public List<tblUsers> GetPersons()
    {
        using (var db = new PersonsEntities())
        {
            return db.tblUsers.ToList();
        }
    }
}

The magical configuration, which is puzzled together all day long from various posts whose I found here:

<bindings>
  <basicHttpBinding>
    <binding name="BindingConfig" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
      <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="PersonSvcBehavior">
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceMetadata httpGetEnabled="true" />
      <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="PersonSvcBehavior" name="WebService.PersonService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BindingConfig"
      name="PersonSvcBasicHttpBinding" contract="WebService.IPersonService" />
    <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="BindingConfig"
      name="PersonSvcMexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:1569/webservice" />
      </baseAddresses>
    </host>
  </service>
</services>

And at the beautiful end I got this, still talking about metadata, but what I do know that I got that MetadataExchange:
enter image description here

Upvotes: 0

Views: 1274

Answers (1)

Rahul
Rahul

Reputation: 77926

Look at your mex endpoint as shown below, specifically the bindingConfiguration part which is totally wrong cause that binding configuration is for basicHttpBinding whereas in this endpoint you are using different binding mexHttpBinding.

<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="BindingConfig"
  name="PersonSvcMexHttpBinding" contract="IMetadataExchange" />

Remove the part bindingConfiguration="BindingConfig" and it should just be

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

Moreover the biggest issue with your configuration is your address <add baseAddress="http://localhost:1569/webservice" /> which is not correct. It should be <add baseAddress="http://localhost:1569/PersonService" />.

So change your <Services> part to be like below

<services>
  <service behaviorConfiguration="PersonSvcBehavior" name="WebService.PersonService">
    <endpoint address="PersonService" binding="basicHttpBinding" bindingConfiguration="BindingConfig"
      name="PersonSvcBasicHttpBinding" contract="WebService.IPersonService" />
    <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:1569/" />
      </baseAddresses>
    </host>
  </service>
</services>

Upvotes: 2

Related Questions