2009-11-15 105 views
0

我創建了一個非常簡單的WCF,並通過執行「複製網站」將其部署到託管提供商。在本地,它設置爲使用開發服務器(不在IIS中)。該域處於完全信任權限下。在本地,我可以訪問Service.svc頁面,但不在託管提供商。無法部署簡單的WCF - 獲取「無法找到資源」

的代碼如下:

Service.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" Factory="CustomHostFactory" %> 

Service.cs

// NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config and in the associated .svc file. 
public class Service : IService 
{ 
    public string GetData(int value) 
    { 
     return string.Format("You entered: {0}", value); 
    } 

    public CompositeType GetDataUsingDataContract(CompositeType composite) 
    { 
     if (composite.BoolValue) 
     { 
      composite.StringValue += "Suffix"; 
     } 
     return composite; 
    } 
} 


class CustomHostFactory : ServiceHostFactory 
{ 
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) 
    { 
     // If more than one base address exists then return the second address, 
     // otherwise return the first address 
     if (baseAddresses.Length > 1) 
     { 
      return new ServiceHost(serviceType, baseAddresses[1]); 
     } 
     else 
     { 
      return new ServiceHost(serviceType, baseAddresses[0]); 
     } 
    } 
} 

class CustomHost : ServiceHost 
{ 
    public CustomHost(Type serviceType, params Uri[] baseAddresses) 
     : base(serviceType, baseAddresses) 
    { } 
} 

的Web.config

<system.serviceModel> 
    <services> 
     <service name="Service" behaviorConfiguration="ServiceBehavior"> 
     <!-- Service Endpoints --> 
     <endpoint address="" binding="wsHttpBinding" contract="IService"> 
      <!-- 
       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. 
      --> 
      <identity> 
      <dns value="localhost"/> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="ServiceBehavior"> 
      <!-- 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> 
    </system.serviceModel> 

任何幫助嗎?

回答

1

有幾件事情:

  • 你創建你的託管服務提供商的虛擬目錄? * .svc文件必須部署到虛擬目錄的根目錄中

  • 您是否導航到http://yourserver/virtualdirectory/yourservice.svc?當在IIS託管,所有的基址東西是沒有實際意義,將被忽略 - 服務的地址是由Web服務器名稱,虛擬目錄定義,名稱* .svc文件

+0

我創建了一個虛擬目錄(名稱:WCFService),目標類型是一個指向wwwroot的文件夾。我有我的所有文件在wwwroot下,所以文件夾結構如下所示: wwwroot - > App_Code,App_Data,Service.svc,Web.config。 然後我瀏覽到http://aa.xx.com/WCFService/Service.svc,並得到相同的錯誤 – Nick 2009-11-15 17:57:49

+0

我也將所有文件移動到wwwroot \ WCFService文件夾後嘗試過,但遇到同樣的問題:( – Nick 2009-11-15 18:07:40

+0

你有沒有得到這個工作?我有同樣的問題,並真正搭上這個工作。 – ElHaix 2009-11-24 19:29:25

0

我剛剛結束了有同樣的問題。您是否使用Rob Zelt文章中的CustomHostFactory:WCF: This collection already contains an address with scheme http

傳入的baseAddresses將包含爲IIS設置的所有綁定;主機頭,端口,http/https。您傳遞給ServiceHost的綁定需要匹配WCF請求到達的URL - 否則您將獲得「無法找到資源」。