我創建了一個非常簡單的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>
任何幫助嗎?
我創建了一個虛擬目錄(名稱: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
我也將所有文件移動到wwwroot \ WCFService文件夾後嘗試過,但遇到同樣的問題:( – Nick 2009-11-15 18:07:40
你有沒有得到這個工作?我有同樣的問題,並真正搭上這個工作。 – ElHaix 2009-11-24 19:29:25