简体   繁体   English

WCF托管在Windows服务+网页中?

[英]WCF hosted in Windows service + web page?

I am not sure if I am about to ask a noddy question, but here it goes. 我不确定我是否要提出一个难以理解的问题,但现在就这样了。 I have a WCF service hosted in a Windows service and a new requirement has come in: A keepalive web page necessary for load balancing. 我有一个托管在Windows服务中的WCF服务,并且有一个新的要求:负载平衡所需的keepalive网页。 Is it possible to host this page from my Windows service? 是否可以从我的Windows服务托管此页面?

Do I need to resort to hosting the WCF service in IIS? 我是否需要在IIS中托管WCF服务? I would prefer not to do this. 我宁愿不这样做。

Thank you. 谢谢。

尝试创建服务契约以处理使用basicHttpBinding公开的loadbalancer的请求

More than one year later, I hope this can help 一年多以后,我希望这可以提供帮助

http://msdn.microsoft.com/en-us/library/bb412178.aspx http://msdn.microsoft.com/en-us/library/bb412178.aspx

How to: Create a Basic WCF Web HTTP Service 如何:创建基本WCF Web HTTP服务

Look at the contract: 看合同:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet]
    string EchoWithGet(string s);

    [OperationContract]
    [WebInvoke]
    string EchoWithPost(string s);
}

you have the request (or post request) in 's' param and you must write the output html in the return. 你有's'参数中的请求(或发布请求),你必须在回报中写出输出html。 That's all 就这样

Your windows service may expose an HTTP endpoint by basicHttpBinding or wsHttpBinding. 您的Windows服务可能会通过basicHttpBinding或wsHttpBinding公开HTTP端点。 IIS is not required. IIS不是必需的。 To host an HTTP endpoint via IIS has some benefits though like message based activation. 通过IIS托管HTTP端点虽然有基于消息的激活,但有一些好处。

And if IIS is already running on the same machine be sure to pick a port different from 80 for your windows service HTTP endpoint since IIS will listen to requests on port 80 and then the requests wouldn't reach your service. 如果IIS已经在同一台机器上运行,请务必为Windows服务HTTP端点选择一个不同于80的端口,因为IIS将侦听端口80上的请求,然后请求将无法到达您的服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM