是否可以通过httpwebrequest使用WCF服务(托管为Windows服务托管)? [英] Is it possible to consume WCF service (which is hosted as windows service hosting) through httpwebrequest?

查看:77
本文介绍了是否可以通过httpwebrequest使用WCF服务(托管为Windows服务托管)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have to create a windows service for reading some machines data for the customer client application. But, I dont have option host the service in IIS. Customer can only consume the service through web url using webrequest. Is there any possibility to consume the WCF service hosted in windows service using webrequest.

Hosting method should not be in IIS and consuming the service should be a type of webrequest (I dont have any idea on this). client will only call net.tcp,http URL types to consume the service.

Thanks in advance.





我的尝试:



我在很多网站上搜索但是我很无奈



What I have tried:

I searched in many websites but i'm helpless

推荐答案

是的,这是可能的,你所要做的就是使您的代码充当基本Web服务器。监听端口(它不必是端口80,如果IIS在计算机上运行,​​它可能必须是80以外的其他东西)并且当请求进入时它将是一个http请求消息。 />


HTTP / 1.1:请求 [ ^ ]



了解HTTP请求的最简单方法是使用浏览器中的调试工具,并在请求页面时查看网络选项卡,格式非常简单。一旦您的服务收到消息,解析请求并执行完成请求所需的任何工作并返回格式正确的响应。再次,您可以通过查看浏览器调试工具中的响应来确定响应应该是什么样的。



如果你谷歌搜索类似c#make basic web的内容服务器你可能会发现很多代码已经存在。
Yes it's possible, all you have to do is make your code act as a basic web server. Listen on a port (it doesn't have to be port 80, if IIS is running on the machine it will probably have to be something other than 80 though) and when a request comes in it will be an http request message.

HTTP/1.1: Request[^]

The easiest way to understand what HTTP requests look like is to use the debug tools in your browser and look at the network tab as you request pages, the format is quite simple. Once your service has received a message, parse the request and do whatever work is required to fulfil the request and return an appropriately formatted response. Again you can work out what the response should look like by looking at responses in the debug tools of your browser.

If you google for something like "c# make basic web server" you'll probably find a lot of the code is out there already.


这篇关于是否可以通过httpwebrequest使用WCF服务(托管为Windows服务托管)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆