【问题标题】:WCF service does not startWCF 服务未启动
【发布时间】:2013-06-21 23:19:25
【问题描述】:

我真的很抱歉再次问这个问题。有类似的帖子,但没有一个解决方案对我有用。

我在 VisualStudio2010 中创建了一个新的 WCF 服务项目。它创建了一个 IService1.cs、Service1.svc 和 Service1.svc.cs

所以,当我尝试调试/启动服务时,我收到以下错误。我正在运行 Win7 x64。我正在使用集成的 VisualStudio 开发服务器(右键单击项目 --> 转到“Web”页面)。

类型“Projector.Service1”,作为服务属性值提供 在 ServiceHost 指令中,或在配置元素中提供 system.serviceModel/serviceHostingEnvironment/serviceActivations 可以 找不到。

知道如何在不运行 IIS 的情况下解决这个问题吗?

提前致谢。

Service1.svc 只包含一行:

<%@ ServiceHost Language="C#" Debug="true" Service="Projector.Service1" CodeBehind="Service1.svc.cs" %>

Service1.svc.cs 包含一个自动生成的类:

namespace Projector
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1

这是 Web.config

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

【问题讨论】:

  • 你有没有编译错误?
  • 你能发布你的配置文件部分 .. 吗?
  • @vendettamit 我在上面添加了 Web.config

标签: c# wcf web-services


【解决方案1】:

解决了这个问题

这是关于在 IIS 8 上发布 WCF 服务的全部内容

所有的功劳都归于 György Balássy

WCF 服务不能在默认配置的 IIS 8 上运行,因为 Web 服务器不知道如何处理以 .svc 文件为目标的传入请求。你可以分两步教它:

请在此处检查相同的答案。

https://stackoverflow.com/a/45979587/3059688

【讨论】:

    【解决方案2】:

    AFAIK,如果您不使用 IIS,svc 将毫无用处。在 IIS 之外,所谓的自托管方法需要您编写类似这样的内容,其中 HelloWorldWcfServiceMessage 是您实现服务契约的类型。另外,不要忘记为服务器配置端点,并确保允许您在配置的端口上打开服务。您可以在 Windows 服务或控制台程序中使用以下代码(更适合测试和调试)。希望对您有所帮助,我的问题是正确的。

    ...
    this.serviceHost = new ServiceHost(typeof(HelloWorldWcfServiceMessage));
    this.serviceHost.Open();
    ...
    
    public class HelloWorldWcfServiceMessage : IHelloWorldWcfServiceMessage
    {
    
    }
    
    [ServiceContract(Namespace = "http://HelloWorldServiceNamespace", Name = "PublicHelloWorldWCFService")]
    public interface IHelloWorldWcfServiceMessage
    {
        [OperationContract]
        string HelloWorldMessage(string name);
    }
    

    【讨论】:

    • 我目前正在尝试这个解决方案。但是我想在 ServiceHost 的构造函数中设置一个自己的 uri(带端口的 HTTP)作为第二个参数,但是我得到一个异常,它已经包含一个 HTTP 地址。您将如何配置 EndPoint?
    • 已修复。我不得不更改 App.config 文件并在那里删除/修复 EndPoint。
    • 好。 app.config 是此配置的正确位置。
    【解决方案3】:

    我认为名称有些混乱。

    在您写的 SVC 中: CodeBehind="Service1.svc.cs" 但是你说你的文件名是Service.svc.cs(没有1)。

    【讨论】:

    • 不,抱歉。这只是写问题时的拼写错误。实际代码是正确的。我在上面解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 2011-06-02
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    相关资源
    最近更新 更多