简体   繁体   English

在Azure中的IIS中使用net.tcp绑定托管WCF服务

[英]Host WCF service with net.tcp binding in IIS in Azure

I am trying to host a WCF service with a net.tcp binding in IIS in Azure according this article http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was-and-iis-on-windows-azure.aspx . 我试图根据本文http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was在Azure中的IIS中托管带有net.tcp绑定的WCF服务和iis-on-windows-azure.aspx But it has not any effect. 但这没有任何作用。

I try to do the folowing: Create CloudService Create WCF web-role In web-role project create folder Startup and place two files there: Startup.cmd 我尝试执行以下操作:创建CloudService创建WCF Web角色在Web角色项目中,创建文件夹Startup并在其中放置两个文件:Startup.cmd

    powershell -command "set-executionpolicy Unrestricted" >> out.txt

RoleStart.ps1 RoleStart.ps1

    import-module WebAdministration 

    # Starting the listener service 
    $listenerService = Get-WmiObject win32_service -filter "name='NetTcpActivator'" 
    $listenerService.ChangeStartMode("Manual")
    $listenerService.StartService()
    $listenerService = Get-WmiObject win32_service -filter "name='NetTcpPortSharing'" 
    $listenerService.ChangeStartMode("Manual")
    $listenerService.StartService()

    $WebRoleSite = (Get-WebSite "*webrole*").Name
    Get-WebApplication -Site $WebRoleSite | Foreach-Object { $site = "IIS:/Sites/$WebRoleSite" +                               $_.path; Set-ItemProperty $site -Name EnabledProtocols 'http,net.tcp'}
    New-ItemProperty "IIS:/Sites/$WebRoleSite" -name bindings -value          @{protocol="net.tcp";bindingInformation="808:*"}

I also added net.tcp endpoint to Role properties with port 808. 我还通过端口808将net.tcp终结点添加到Role属性。

First fail when i try to publish - role cyclic starts and stops. 当我尝试发布时第一次失败-角色循环开始和停止。 But when I disable Startup.cmd, it publishes successfully. 但是,当我禁用Startup.cmd时,它将成功发布。

But even in this case, I can't resolve service reference. 但是即使在这种情况下,我也无法解析服务引用。

What I must to do that this service will work? 我必须做些什么才能使该服务正常工作?

Make sure that in your Service Definition file that your executionContext is set to 'elevated'. 确保在服务定义文件中将executionContext设置为“ elevated”。 See this MSDN post for more details on the options available. 有关可用选项的更多详细信息,请参见此MSDN帖子

But when I disable Startup.cmd, it publishes successfully. 但是,当我禁用Startup.cmd时,它将成功发布。

I see this a lot with startup files in cloud services. 我在云服务中的启动文件中看到了很多。 If you RDP into your instance and try to run the Startup.cmd from a command prompt, then you will likely see the problem. 如果您将RDP放入实例并尝试在命令提示符下运行Startup.cmd,则很可能会看到问题。 I'm willing to bet (hence the reason I'm providing this as an answer and not a comment) is that the encoding of the Starup.cmd and/or Rolestart.ps1 are not being interpreted correctly on the machine your cloud service is deployed to. 我愿意打赌(因此,我将其作为答案而不是提供评论的原因)是,Starup.cmd和/或Rolestart.ps1的编码在您的云服务所在的计算机上未正确解释部署到。 When saving these files, you need to save them using codepage 65001 (UTF 8 w/out signature) instead of the default 1252. Do this and it should resolve your problem. 保存这些文件时,您需要使用代码页65001(UTF 8 w / out签名)而不是默认的1252保存它们。这样做可以解决您的问题。

I show how to do this in my blog and also provide a step-by-step solution for what you're trying to do at http://rickrainey.com/2013/08/30/hosting-a-wcf-service-in-an-azure-web-role-with-http-tcp-endpoints/ . 我在博客中展示了如何执行此操作,还通过http://rickrainey.com/2013/08/30/hosting-a-wcf-service-提供了您要执行的操作的分步解决方案在具有http-tcp-endpoints /的Azure Web角色中 And if you're interested in securing your WCF service, you may want to check out the 2nd post at http://rickrainey.com/2013/09/18/securing-a-wcf-service-in-an-azure-web-role-with-http-tcp-endpoints-2/ . 如果您有兴趣保护WCF服务,则可以在http://rickrainey.com/2013/09/18/securing-a-wcf-service-in-an-azure-中查看第二篇文章。 web-role-with-http-tcp-endpoints-2 /

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

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