首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用WCF而不指定uri

使用WCF而不指定uri
EN

Stack Overflow用户
提问于 2011-05-13 06:33:54
回答 4查看 1.7K关注 0票数 1

如何使用WCF而不指定uri/url/baseaddress地址?是否有办法使它自动获得这些东西?

我的意思是,我希望让它像asp.net站点一样工作,在这里我们没有提到uri和其他东西,只要我们在IIS中正确配置它,它就会自己处理它。我需要一个类似的WCF解决方案。

请帮帮我..。

谢谢你。

编辑:这是我的服务器端代码,我在这里使用自定义的ServiceHostFactory .

代码语言:javascript
复制
 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;
    }
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-05-13 12:33:30

(假设你是针对IIS.)

根据部署Internet信息服务-托管WCF服务文档:

..。托管在IIS中的服务无法控制其基址;IIS承载的服务的基址是其.svc文件的地址。

您的自定义服务主机逻辑是否可能停止了此行为?

更新:根据函数docs,您只需将一个相对地址传递给AddServiceEndpoint调用。尝试空字符串或"/“。

票数 3
EN

Stack Overflow用户

发布于 2011-05-13 07:01:44

查看一下WCF发现,它允许您动态地找到端点。

票数 2
EN

Stack Overflow用户

发布于 2011-05-13 13:15:52

我认为你需要对你的代码做的就是:

代码语言:javascript
复制
servicehost.AddServiceEndpoint(typeof(IService), basichttpbinding, "");

去完成你想要的。正如@Schneider所指出的,IIS控制服务地址的分配。端点地址将始终相对于IIS分配地址。因此,基于IIS的端点的唯一有效值如下:

代码语言:javascript
复制
servicehost.AddServiceEndpoint(typeof(IService), basichttpbinding, "MyService");

它将把MyService附加到服务URL。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5988113

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档