Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 遇到WCF问题:HTTP错误404.0-未找到_C#_Asp.net_Rest_Wcf - Fatal编程技术网

C# 遇到WCF问题:HTTP错误404.0-未找到

C# 遇到WCF问题:HTTP错误404.0-未找到,c#,asp.net,rest,wcf,C#,Asp.net,Rest,Wcf,问题 我正在尝试使用WCF创建Rest服务。我在调用堆栈名称空间中创建了一个名为“Coronado.HUB”的WCF类,如下所示。当我向服务发出http请求时,我得到一个404错误 源代码 using Coronado.HUB.Model; using Coronado.HUB.Service; using System; using System.ServiceModel; using System.ServiceModel.Web; namespace Coronado.HUB {

问题

我正在尝试使用WCF创建Rest服务。我在调用堆栈名称空间中创建了一个名为“Coronado.HUB”的WCF类,如下所示。当我向服务发出http请求时,我得到一个404错误

源代码

using Coronado.HUB.Model;
using Coronado.HUB.Service;
using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace Coronado.HUB
{
    /// <summary>
    /// Returns Driver By ID
    /// </summary>
    [ServiceContract]
    public interface IDriverService
    {
        [OperationContract]
        [WebGet]
        Driver GetDriverById(Guid id);
    }

    /// <summary>
    /// Returns Driver Object By ID
    /// </summary>
    public class DriverService : IDriverService
    {
        public Driver GetDriverById(Guid id)
        {
            return DriverServiceProvider.Instance.GetDriverById(id);
        }
    }
}

我遇到的问题是由于WCF未向IIS注册而导致的。据我所知,在.NET4.0之前,这是通过命令行完成的。就我而言,我使用了程序和功能。这就解决了问题


有关其他信息,请参阅:

我遇到的问题是由于WCF未向IIS注册而导致的。据我所知,在.NET4.0之前,这是通过命令行完成的。就我而言,我使用了程序和功能。这就解决了问题


有关更多信息,请参考:

您在项目中使用了哪个项目模板?我想更多地了解你们的项目结构。在我看来,您似乎没有使用WCF服务应用程序项目模板。因此,对服务实现类进行编程可能是无效的。此外,指定的基址无效。它应该在IIS站点绑定模块中配置。您好,Abraham,我确实尝试使用VS项目模板,但遇到了问题。我使用的是几年前完成的另一个实现,目前正在解决这个问题。我逐字使用这些模式来实现上面演示的模式。诚然,这个实现与VS模板不一致,它被认为是一个高效的实现。也许我应该尝试使用现有的项目模板来实现这个功能。是的,这个实现是一个高效的实现。它与项目模板无关。在我试图复制你的问题后,它证明工作正常。你如何主持你的服务?您确定服务地址正确吗?我可以确定WCF未正确注册到IIS。一旦我通过本地机器上的操作系统程序文件和功能在.NET4.7的WCF选项下注册并激活了HTTP,它就工作了。非常感谢您的反馈-这非常有帮助,因为我让这个较旧的实现和VS项目模板都可以工作。我正在讨论是使用VS项目模板还是坚持最初的实现。再次感谢您的帮助。您在项目中使用了哪个项目模板?我想更多地了解你们的项目结构。在我看来,您似乎没有使用WCF服务应用程序项目模板。因此,对服务实现类进行编程可能是无效的。此外,指定的基址无效。它应该在IIS站点绑定模块中配置。您好,Abraham,我确实尝试使用VS项目模板,但遇到了问题。我使用的是几年前完成的另一个实现,目前正在解决这个问题。我逐字使用这些模式来实现上面演示的模式。诚然,这个实现与VS模板不一致,它被认为是一个高效的实现。也许我应该尝试使用现有的项目模板来实现这个功能。是的,这个实现是一个高效的实现。它与项目模板无关。在我试图复制你的问题后,它证明工作正常。你如何主持你的服务?您确定服务地址正确吗?我可以确定WCF未正确注册到IIS。一旦我通过本地机器上的操作系统程序文件和功能在.NET4.7的WCF选项下注册并激活了HTTP,它就工作了。非常感谢您的反馈-这非常有帮助,因为我让这个较旧的实现和VS项目模板都可以工作。我正在讨论是使用VS项目模板还是坚持最初的实现。再次感谢你的帮助。
<%@ ServiceHost Service="Coronado.HUB.DriverService" %>
<system.serviceModel>
    <services>
     <service name="Coronado.HUB.DriverService">
        <endpoint address="" binding="webHttpBinding" contract="Coronado.HUB.IDriverService" behaviorConfiguration="RestService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/XXX/DriverService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="RestService">
          <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
http://localhost/XXX/DriverService.svc/GetDriverById?id=F200A17F-9E03-41EB-90FB-01B8665246BB