无法使用IIS在共享服务器上运行WCF服务

时间:2013-01-04 10:44:31

标签: wcf iis iis-7

我无法使用IIS在共享服务器上运行WCF服务。

我尝试了几个教程: http://technologyriver.blogspot.com/2012/02/prerequisites-check-windows-7.html http://msdn.microsoft.com/en-us/library/ms733766.aspx

我读过有关执行命令行指令的博客,以便在IIS上启用WCF支持。 但是,托管公司拒绝在他们的盒子上运行命令。

我的开发机器上的服务运行正常。 但是,我无法让服务在远程服务器上运行。

单击svc文件时出现以下错误:

HTTP错误404.3 - 未找到

由于扩展程序配置,无法提供您请求的页面。如果页面是脚本,请添加处理程序。如果要下载文件,请添加MIME映射。*

svc文件:

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

的Web.config:

<service name="MyService" behaviorConfiguration="MyServiceBehavior">
    <endpoint contract="IMyService" binding="basicHttpBinding">
      <identity>
        <dns value="http://www.mydomain.com" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

    <host>
      <baseAddresses>
        <add baseAddress="http://www.mydomain.com:8732/Services/Service/" />
      </baseAddresses>
    </host>
  </service>

Service.cs:

using System;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;

// A WCF service consists of a contract (defined below as IMyService, DataContract1), 
// a class which implements that interface (see MyService), 
// and configuration entries that specify behaviors associated with 
// that implementation (see <system.serviceModel> in web.config)

[ServiceContract()]
public interface IMyService
{
    [OperationContract]
    string MyOperation1(string myValue1);
    [OperationContract]
    string MyOperation2(DataContract1 dataContractValue);
}

public class MyService : IMyService
{
    public string MyOperation1(string myValue1)
    {
        return "Hello: " + myValue1;
    }
    public string MyOperation2(DataContract1 dataContractValue)
    {
        return "Hello: " + dataContractValue.FirstName;
    }
}

[DataContract]
public class DataContract1
{
    string firstName;
    string lastName;

    [DataMember]
    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }
    [DataMember]
    public string LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }
}

public class MyServiceHostFactory : ServiceHostFactoryBase
{
    protected virtual ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        // Specify the exact URL of your web service
        Uri webServiceAddress = new Uri("http://www.mydomain.com/MyService.svc");

        MyServiceHost webServiceHost = new MyServiceHost(serviceType, webServiceAddress);
        return webServiceHost;
    }

    public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
    {
        throw new NotImplementedException();
    }
}

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

    protected override void ApplyConfiguration()
    {
        base.ApplyConfiguration();
    }
}

2 个答案:

答案 0 :(得分:1)

我不得不切换主机。

我最初使用的是DiscountASP.Net,他们拒绝了我的确保WCF设置已启用的请求,并告诉我需要聘请开发人员或遵循MS IIS规范。 (P.S.他们不知道我实际上是SDET。)

结果,我不得不切换到另一个提供者(即Winhost)。 事情现在正常工作,没有我必须做任何疯狂的webconfig改动或ServiceHostFactory编码废话,以前的主机希望我这样做没有成功。

我花了5天时间用他们的技术支持重新开门票,直到我最终切换到实际支持WCF服务的托管公司。

感谢Winhost结束这个可怕的噩梦!

答案 1 :(得分:0)

这似乎是远程服务器上的访问/可配置性问题。

尝试检查已部署服务的以下区域。

  • 正确配置了WCF服务的绑定,DNS和端口(默认为80)
  • 身份验证服务模式(应允许匿名访问浏览器通过WSDL)
  • 授予网站的权限(目录和用户权限)

如果它们都不起作用,那么您可以列出部署服务时遵循的步骤吗?

相关问题