简体   繁体   中英

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. Is it possible to host this page from my Windows service?

Do I need to resort to hosting the WCF service in IIS? 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

How to: Create a Basic WCF Web HTTP Service

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. That's all

Your windows service may expose an HTTP endpoint by basicHttpBinding or wsHttpBinding. IIS is not required. To host an HTTP endpoint via IIS has some benefits though like message based activation.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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