创建DomainService,添加终结点

创建了DomainService,在浏览器里能够看到服务已经创建成功,但是在引用服务的时候出现错误,提示如下

元数据包含无法解析的引用:“http://localhost:27963/Services/MVCDomainService-DomainServiceMain.svc?wsdl”。
无法识别此文档格式(内容类型为“text/html; charset=UTF-8”)。
元数据包含无法解析的引用:“http://localhost:27963/Services/MVCDomainService-DomainServiceMain.svc?wsdl”。
没有终结点在侦听可以接受消息的 http://localhost:27963/Services/MVCDomainService-DomainServiceMain.svc?wsdl。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参见 InnerException 以了解详细信息。
远程服务器返回错误: (404) 未找到。
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。

这是因为在创建DomainService 的时候没有创建终结点导致的,解决方法很简单。

1、在DomainService的程序集中添加引用,引用名称:Microsoft.ServiceModel.DomainServices.Hosting。

2、在DomainService的程序集的配置文件中添加如下配置到配置节点system.serviceModel

<domainServices>
      <endpoints>
        <add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </endpoints>
    </domainServices>

3、重新生成一下DomainService的程序集,然后就能够引用DomainService 了。

原文地址:https://www.cnblogs.com/Simon-Asw/p/3190834.html