未找到WCF端点

本文关键字:端点 WCF | 更新日期: 2023-09-27 18:01:27

我正在遵循一本书中的教程来实现Windows Phone的推送通知。这是服务的标记:

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

如你所见,添加了一个工厂,尽管我不太明白它是干什么的。当运行服务时,我得到一个"endpoint not found"错误。当我从标记中删除工厂时,错误消失了,但我得到一个空页面。

知道什么可能导致这个错误或如何修复它吗?如果你需要更多的代码,请告诉我。

感谢

编辑:我的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>

未找到WCF端点

您的web.config中缺少端点配置。

添加到你的web.config:

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

对于那些没有在Service中实现该方法的人。如果在IService中没有svc的定义,则会导致相同的异常。

这是被遗忘的

[OperationContract]
 string CheckHMAC(string hMac);

但实施

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