如何使用WCF而不指定uri/url/baseaddress地址?是否有办法使它自动获得这些东西?
我的意思是,我希望让它像asp.net站点一样工作,在这里我们没有提到uri和其他东西,只要我们在IIS中正确配置它,它就会自己处理它。我需要一个类似的WCF解决方案。
请帮帮我..。
谢谢你。
编辑:这是我的服务器端代码,我在这里使用自定义的ServiceHostFactory .
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
BasicHttpBinding basichttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basichttpbinding.CloseTimeout=TimeSpan.MaxValue;
basichttpbinding.OpenTimeout=TimeSpan.MaxValue;
basichttpbinding.ReceiveTimeout=TimeSpan.MaxValue;
basichttpbinding.SendTimeout=TimeSpan.MaxValue;
// basichttpbinding.TransferMode = TransferMode.Buffered;
ServiceEndpoint servicepoint=new ServiceEndpoint(ContractDescription.GetContract(serviceType));
servicepoint.Binding=basichttpbinding;
ServiceHost servicehost = new ServiceHost(serviceType, baseAddresses);
((ServiceDebugBehavior)servicehost.Description.Behaviors[typeof(ServiceDebugBehavior)]).IncludeExceptionDetailInFaults=true;
servicehost.OpenTimeout = TimeSpan.MaxValue;
servicehost.CloseTimeout = TimeSpan.MaxValue;
servicepoint.Binding.SendTimeout = TimeSpan.MaxValue;
servicepoint.Binding.ReceiveTimeout = TimeSpan.MaxValue;
basichttpbinding.MaxBufferPoolSize = 999999999;
// basichttpbinding.MaxConnections = 999999999;
//basichttpbinding.MaxConnections = 999999999;
basichttpbinding.MaxReceivedMessageSize = 999999999;
XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
quotas.MaxArrayLength = 999999999;
quotas.MaxBytesPerRead = 999999999;
quotas.MaxDepth = 999999999;
quotas.MaxNameTableCharCount = 999999999;
quotas.MaxStringContentLength = 999999999;
basichttpbinding.ReaderQuotas = quotas;
//foreach (Uri uri in baseAddresses)
//{
servicehost.AddServiceEndpoint(typeof(IService), basichttpbinding, "http://localhost:52855/WCFService1/Service.svc");
// }
return servicehost;
}发布于 2011-05-13 12:33:30
(假设你是针对IIS.)
根据部署Internet信息服务-托管WCF服务文档:
..。托管在IIS中的服务无法控制其基址;IIS承载的服务的基址是其.svc文件的地址。
您的自定义服务主机逻辑是否可能停止了此行为?
更新:根据函数docs,您只需将一个相对地址传递给AddServiceEndpoint调用。尝试空字符串或"/“。
发布于 2011-05-13 07:01:44
查看一下WCF发现,它允许您动态地找到端点。
发布于 2011-05-13 13:15:52
我认为你需要对你的代码做的就是:
servicehost.AddServiceEndpoint(typeof(IService), basichttpbinding, "");去完成你想要的。正如@Schneider所指出的,IIS控制服务地址的分配。端点地址将始终相对于IIS分配地址。因此,基于IIS的端点的唯一有效值如下:
servicehost.AddServiceEndpoint(typeof(IService), basichttpbinding, "MyService");它将把MyService附加到服务URL。
https://stackoverflow.com/questions/5988113
复制相似问题