2009-01-16 82 views
19

试图让我的WCF服务IIS 6下运行WCF不IIS下运行6.0

我已经按照创建.svcaspnet_isapi.dll映射:http://msdn.microsoft.com/en-us/library/ms752241.aspx

当查看Server1.svc页面,我得到一个404.

我已经用简单的.aspx页面测试过该网站,以确保网址正常,但是.svc扩展名不是。

我已经安装了.NET 3.5 SP1,我的web.config引用了3.5个程序集,并且在查看.aspx页面时我没有看到错误,因此它正在挑选那些程序集,估计是这样。

什么可能是错的?

+1

这是在远程服务器上orlocalhost?如果偏远,你是否先验证了本地所有工作? – 2009-01-17 17:59:07

回答

6

有两件事我能想到的:

.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" %> 
+0

有没有主机头,我可以看到,只是使用IP – Blankman 2009-01-16 21:41:26

+1

你可能还没有解决OP的问题,但你有我的! – RSolberg 2010-04-06 22:23:13

20

更可能的.svc扩展名是不是IIS下注册为被处理由ASP.NET(WCF)。

尝试以下2个步骤(如果它需要与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 
+0

这对我有用!谢谢 – 2009-01-28 15:06:49

17

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

3

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

我不知道为什么没有人在我读到的30条线索中的任何其他地方提到过,但我的朋友向我推荐了它,它的功能就像一个魅力。

只是为了防万一有人有同样的问题扔在那里。

0

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

0

我争夺这一小时,直到最后我用这个例子,它的工作先去:http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide

我知道唯一的链接的答案是不好的,别人都用这个CP链接solve this type of problem here at Stackoverflow所以这里如果文章不断下降的基本步骤:

STEP 1

首先推出的Visual Studio 2010中点击文件 - >新建>项目。创建新的“WCF服务应用程序”。

STEP 2

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

第3步

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

STEP 4

正如我在,我们会写,在XML和JSON格式返回数据的API的文章开始解释,这里是该接口。在IRestServiceImpl中,添加以下代码

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

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

STEP 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> 

STEP 7

在IIS:

enter image description here