【问题标题】:WCF not running under IIS 6.0WCF 不在 IIS 6.0 下运行
【发布时间】:2010-10-01 21:21:23
【问题描述】:

试图让我的 WCF 服务在 IIS 6 下运行。

我创建了 .svcaspnet_isapi.dll 映射根据:http://msdn.microsoft.com/en-us/library/ms752241.aspx

查看Server1.svc 页面时,我收到了 404。

我已经用一个简单的 .aspx 页面测试了该网站,以确保 URL 正常工作,但 .svc 扩展名再次不起作用。

我安装了 .NET 3.5 SP1,我的 web.config 正在引用 3.5 程序集,并且在查看 .aspx 页面时我没有收到错误,因此它可以很好地拾取这些程序集,大概是。

可能出了什么问题?

【问题讨论】:

  • 这是在远程服务器还是本地主机上?如果是远程的,您是否先在本地验证一切正常?

标签: wcf web-services configuration iis-6


【解决方案1】:

.svc 扩展名很可能未在 IIS 下注册为由 ASP.NET (WCF) 处理。

尝试以下 2 个步骤(如果需要,将 Framework 替换为 Framework64):

转到:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\

然后运行:

aspnet_regiis -i

转到: C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation

然后运行:

ServiceModelReg.exe -i

【讨论】:

  • 这是一个救生员!我只需要运行“aspnet_regiis”并修复它。
  • 如果你运行 - 我不会“破坏”所有之前的 .net 安装吗?我们的整个网站都在运行 .net 1... 我需要让 wcf 正常工作。我应该使用 -i 标志运行吗?我不想改变任何现有的东西。
【解决方案2】:

Internet Information Service (IIS) Manager 下,打开名为Web Service Extension 的节点。确保 ASP.NET v2.0.5.0727 设置为允许。我花了几个小时寻找不同的设置,发现它被设置为禁止。只需单击“允许”按钮即可启用 ASP.NET。

【讨论】:

  • 谢谢你,你刚刚修复了我的部署!
  • 这是给我的。其他一切都已设置好。谢谢:)
【解决方案3】:

我能想到两件事:

.svc 扩展名设置不正确(根据您的描述,可能性最小)。您可以查看post 了解更多详情。

或者您的网站有多个主机标头。要解决此问题,您必须有一个主机标头或使用工厂。这是一个例子:

namespace MyNamespace
{
    public class MultipleHostServiceFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            List<Uri> addresses = new List<Uri>();
            addresses.Add(baseAddresses[0]);
            return base.CreateServiceHost(serviceType, addresses.ToArray());
        }
    }
}

接下来,您需要在 .svc 文件的标记中设置工厂:

<%@ ServiceHost Language="C#" 
                Debug="false" 
                Factory="MyNamespace.MultipleHostServiceFactory" 
                Service="MyNamespace.MyService" 
                CodeBehind="MyService.svc.cs" %>

【讨论】:

  • 我可以看到没有主机标头,仅使用 IP
【解决方案4】:

我遇到了同样的问题。结果是我运行的是 64 位版本的 Windows 2003 Server,并且我的程序集配置为“任何 CPU”。一旦我将程序集更改为 x86 并上传到服务器,一切正常。

我不知道为什么在我读到的 30 个线程中没有人提到它,但我的朋友向我推荐了它,它就像一个魅力。

只是把它扔在那里以防万一有人遇到同样的问题。

【讨论】:

    【解决方案5】:

    我遇到了同样的问题,并通过允许 ISAPI 扩展解决了它。在 Internet 信息服务 (IIS) 管理器下,打开名为 Web 服务扩展的节点。确保“所有未知的 ISAPI 扩展”设置为允许。

    【讨论】:

      【解决方案6】:

      我为此奋斗了好几个小时,直到我最终使用了这个示例并且它首先成功了:http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

      我知道只有链接的答案不好,其他人已经使用此 CP 链接到 solve this type of problem here at Stackoverflow 所以如果文章失败,以下是基本步骤:

      第 1 步

      首先启动 Visual Studio 2010。单击 FILE->NEW->PROJECT。创建新的“WCF 服务应用程序”。

      第 2 步

      创建项目后,您可以在解决方案中看到默认情况下已创建 WCF 服务和接口文件(Service1.cs 和 IService.cs)。删除这两个文件,我们将创建自己的接口和 WCF 服务文件。

      第 3 步

      现在右键单击解决方案并创建一个新的 WCF 服务文件。我已将服务文件命名为“RestServiceImpl.svc”。

      第 4 步

      正如我在文章开头所解释的,我们将编写一个可以返回 XML 和 JSON 格式数据的 API,这里是它的接口。在IRestServiceImpl中,添加如下代码

      在上面的代码中,您可以看到 IRestService 的两种不同方法,即 XMLData 和 JSONData。 XMLData 以 XML 形式返回结果,而 JSONData 以 JSON 形式返回。

      [ServiceContract]
      public interface IRestServiceImpl
      {
          [OperationContract]
          [WebInvoke(Method = "GET",
              ResponseFormat = WebMessageFormat.Xml,
              BodyStyle = WebMessageBodyStyle.Wrapped,
              UriTemplate = "xml/{id}")]
          string XMLData(string id);
      
          [OperationContract]
          [WebInvoke(Method = "GET",
              ResponseFormat = WebMessageFormat.Json,
              BodyStyle = WebMessageBodyStyle.Wrapped,
              UriTemplate = "json/{id}")]
          string JSONData(string id);
      }
      

      第 5 步

      打开文件 RestServiceImpl.svc.cs 并在其中编写以下代码:

      public class RestServiceImpl : IRestServiceImpl
      {
          public string XMLData(string id)
          {
              return "You requested product " + id;
          }
      
          public string JSONData(string id)
          {
              return "You requested product " + id;
          }
      }
      

      第 6 步

      Web.Config

      <?xml version="1.0"?>
      <configuration>
        <system.web>
          <compilation debug="true" targetFramework="4.0" />
        </system.web>
        <system.serviceModel>
          <services>
            <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
              <!-- Service Endpoints -->
              <!-- Unless fully qualified, address is relative to base address supplied above -->
              <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
                <!-- 
                    Upon deployment, the following identity element should be removed or replaced to reflect the 
                    identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                    automatically.
                -->
              </endpoint>
            </service>
          </services>
      
          <behaviors>
            <serviceBehaviors>
              <behavior name="ServiceBehaviour">
                <!-- 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>
            <endpointBehaviors>
              <behavior name="web">
                <webHttp/>
              </behavior>
            </endpointBehaviors>
          </behaviors>
          <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        </system.serviceModel>
        <system.webServer>
          <modules runAllManagedModulesForAllRequests="true"/>
        </system.webServer>
      </configuration>
      

      第七步

      在 IIS 中:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-23
        • 2012-03-14
        • 1970-01-01
        • 2011-01-01
        • 2011-08-18
        相关资源
        最近更新 更多