WCF服务元数据错误

时间:2016-01-06 18:39:32

标签: c# entity-framework web-services wcf

我正在尝试开发一个WCF服务但是我一个接一个地得到了几个错误WCFTestClient正在推出,我正在尝试解决它们,整天看几个教程并在这里阅读帖子,但是这个我无法想象为什么会发生这种情况,我做错了什么以及如何解决它。 但首先,环境,我在Visual Studio 2013的开发过程中,调试,在IIS或其他地方没有任何东西托管。到目前为止看起来像这样:
WCF service project
模型: EntityFramework模型,没有什么大的实验来自我在开发PC上的本地数据库。
WebService:我正在努力开发的WCF Web服务,但现在还没有成功。 在 IPersonService 类代码中是这样的:

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

PersonService.svc 代码中是这样的:

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

神奇的配置,我在这里找到的各种帖子整天都很困惑:

<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>

在美丽的一端,我得到了这个,仍在谈论元数据,但我知道我得到了MetadataExchange:
enter image description here

1 个答案:

答案 0 :(得分:2)

查看您的mex端点,如下所示,特别是bindingConfiguration部分,这是完全错误的,因为绑定配置是针对basicHttpBinding的,而在此端点中,您使用的是不同的绑定{{ 1}}。

mexHttpBinding

删除部分<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="BindingConfig" name="PersonSvcMexHttpBinding" contract="IMetadataExchange" /> ,它应该只是

bindingConfiguration="BindingConfig"

此外,您的配置最大的问题是您的地址<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> ,这是不正确的。它应该是<add baseAddress="http://localhost:1569/webservice" />

因此,将您的<add baseAddress="http://localhost:1569/PersonService" />部分更改为如下所示

<Services>
相关问题