我无法让 WCF 服务在使用 IIS 的共享服务器上运行。
我尝试了几个教程: 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" %>
网络配置:
<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>
服务.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();
}
}