繁体   English   中英

WCF服务无法启动

[英]WCF service does not start

非常抱歉再次提出这个问题。 也有类似的帖子,但是没有一种解决方案对我有用。

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

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

找不到类型'Projector.Service1',作为ServiceHost指令中的Service属性值提供,或在配置元素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>

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);
}

我认为名称有些混乱。

在SVC中,您编写了:CodeBehind =“ Service1.svc.cs”但您说的文件名为Service.svc.cs(不带1)。

解决了这个

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

所有的功劳归于GyörgyBalássy

WCF服务无法在具有默认配置的IIS 8上运行,因为Web服务器不知道如何处理针对.svc文件的传入请求。 您可以分两步进行讲授:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM