2009-01-16 76 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