2009-11-15 57 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 - 否则您将获得“无法找到资源”。