将 HttpListener 转换为在 IIS 中运行
我听说有一些方法可以获取使用 HttpListener 的 C# 应用程序并对其进行更改,以便它可以在 IIS 中运行,但我找不到任何具体的参考资料。有人对这个主题有什么想法可以分享吗?
I've heard that there are ways to take a C# app that uses HttpListener and change it such that it will run in IIS but I'm unable to find any concrete references on this. Does anyone have any ideas on the topic that they could share?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这里找到了我要找的东西:http://support.microsoft.com/kb/308001
看起来只需要实现一些小的代码更改。希望这也可以帮助其他人。
编辑 2019 年 6 月 21 日
@Vermin 询问我是否能找到该链接,但我找不到,但我确实找到了我的一个非常旧的代码库,其中包含一些令人尴尬的代码,至少可以提供一些起始信息点/方向(希望对其他人也适用)。如果我没有很好地解释其中一些项目背后的“原因”,请原谅我(那是不久前的事,我没有充分理解它)。
1)ServiceContract
2)我还必须提供一个内容映射器(我不太记得为什么)
3)然后我需要在 web.config 中做一些事情...
我还在评论中看到了这个链接项目,这可能有用: http://www.codehosting.net/blog/BlogEngine/post/WebContentFormatRaw-in-your-WCF-config-file
如果我不能真正解释'为什么'以上所有。其中一些很容易理解(映射 GET、POST 方法),其中一些我觉得我只是在尝试一些东西(web.config 的东西)。
对于某些上下文,我记得我正在迁移的应用程序具有处理所有底层 HTTP 连接等的代码,一旦我使用上述内容将其迁移到 IIS,并不是说它非常脆弱,我只是觉得尽管我失去了很多控制权,但没有真正理解如何或为什么,并且需要做出改变确实让我觉得它很脆弱。这是我构建 Watson Webserver(无耻插件)来快速构建 RESTful 服务器的原因之一: https ://www.nuget.org/packages/Watson/2.0.5
I found what I was looking for here: http://support.microsoft.com/kb/308001
Looks like there are only minor code changes that would need to be implemented. Hope this can help someone else, too.
Edit 6/21/19
@Vermin asked if I could find the link, which I could not, but I did find a really old code base of mine with some embarassing code that may at least provide some starting points/directions (hopefully for others too). Please forgive me if I don't provide good clarity on the 'why' behind some of these items (it was a while ago, and I didn't understand it all to the depth I should have).
1) The ServiceContract
2) I also had to provide a content mapper (I can't really remember why)
3) Then there was something I needed to do in web.config...
I also saw this link in the comments of the project, which may prove useful: http://www.codehosting.net/blog/BlogEngine/post/WebContentFormatRaw-in-your-WCF-config-file
You'll have to forgive me if I can't really explain the 'why' of all of the above. Some of it is easy to understand (mapping the GET, POST methods), some of it I felt like I was just trying things (the web.config stuff).
For some context, I recall the app I was migrating had code to deal with all of the underlying HTTP connections and such, and once I migrated it to IIS using the above, it wasn't that it was terribly fragile, I just felt as though I lost a lot of control without actually understanding the how or the why, and needing to make changes did cause me to feel it was fragile. It's one of the reasons I built Watson Webserver (shameless plug) for quickly building RESTful servers: https://www.nuget.org/packages/Watson/2.0.5
它是否编译为可以在命令行上启动的exe?如果是这样:
Azure 项目有一个钩子,您可以使用它来启动需要在后台运行的第 3 方应用程序。我建议您创建一个辅助角色,添加一个端点以在 Azure 中打开必要的端口。将现有可执行文件添加为项目中的项目(将其设置为复制本地),并通过服务定义文件中的后台任务启动它。
Steve Marx 有一篇关于如何执行此操作的精彩博客文章:http://blog.smarx.com/posts/using-other-web-servers-on-windows-azure
Is it compiled as an exe you can start on the command line? If so:
Azure projects have a hook you can use to start 3rd party applications that need to run in the background. I suggest you create a Worker Role, add an endpoint to open the necessary port in Azure. Add your existing executable as an item in the project (setting it to copy local), and start it with a background task in the service definition file.
Steve Marx has a good blog post on how to do this here: http://blog.smarx.com/posts/using-other-web-servers-on-windows-azure