简体   繁体   中英

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服务项目
EntityFramework model, nothing big just one table for experiments which is coming from my local DB which is on development PC. EntityFramework模型,没有什么大不了的,只是一张来自于开发PC上本地DB的实验表。
WCF web service which I'm trying to develop all day long without success by now. WCF Web服务,我正在努力开发一整天,但到目前为止没有成功。 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:
在此处输入图片说明

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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