WCF终结点未找到。

5

我正在跟随一本书的教程实现Windows Phone推送通知。以下是服务的标记:

<%@ ServiceHost Language="C#" Debug="true" Service="Service.PushService" CodeBehind="PushService.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

你可以看到,一个工厂被添加了进来,不过我实际上并不知道它是干什么的。当我运行这个服务时,我收到了一个“终结点未找到”的错误。当我从标记中删除这个工厂时,这个错误就消失了,但我得到了一个空白页面。

有没有想法是什么导致了这个错误或者如何解决它?如果你需要更多的代码,请告诉我。

谢谢

编辑: 我的web.config:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

请发布您的 .config 文件。 - Jocke
阅读此链接:http://msdn.microsoft.com/zh-cn/library/aa702697.aspx - Jocke
我已经添加了.config文件,谢谢。 - Bv202
2
WebServiceHostFactory 用于 REST 端点(WebHttpBinding)。在您的配置中,您没有明确指定任何端点。这意味着您提到的服务主机的默认端点功能将会启动。因此,在您的情况下,WebServiceHostFactory 将尝试添加默认的 REST 端点。删除工厂属性后它能够运行的原因是 - 一旦您删除了工厂属性,就会使用默认的服务主机,该主机会添加基本的 baicHttpBinding 端点。 - Praburaj
@Bv202 你是如何对你的 Web 服务进行“测试”的?endpoint not found错误出现在哪里 - 在浏览器中访问它时?还是在运行服务时?等等。 - Jesse
当浏览到它时,它会出现。 - Bv202
2个回答

9

您的web.config缺少终结点配置。

请在您的web.config中添加以下内容:

<system.serviceModel>
  <services>
    <service name="Service.PushService">
      <endpoint address="" binding="basicHttpsBinding"
                contract="Service.IPushService" />
    </service>
  </services>
</system.serviceModel>

基本的Https绑定还是WebHttp绑定? - EdmundYeung99
<add binding="basicHttpsBinding" scheme="https" />应该保持不变。 - Aron
在填写地址后,如果出现AddressAccessDeniedException异常,则以管理员身份打开Visual Studio。 - alansiqueira27

0

对于那些在 Service.svc 中实现了定义在 IService 中不存在的方法的人,会导致相同的异常。

这是被遗忘的。

[OperationContract]
 string CheckHMAC(string hMac);

但已实现

[WebInvoke(Method = "GET", UriTemplate = "/CheckHMAC/{hMac}")]
public string CheckHMAC(string hMac)
{//}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接