在Azure在本地主机上使用WCF [英] Using WCF on Localhost on Azure
问题描述
综上所述结果
我如何存取权限在本地主机上一个WCF服务托管在IIS上Azure的时候? Azure不绑定本地主机或127.0.0.1到我的网站。
In summary
How do I acces a WCF service on localhost when hosted in IIS on Azure? Azure does not bind localhost or 127.0.0.1 to my website.
详情结果
我有托管在Azure上的ASP.Net应用程序。我添加了一个.SVC以及一些工作流程,我想通过WCF使用。为简单起见,我的web应用程序只需调用localhost上的服务,所以我有这样的在web.config中的端点;
Details
I have an ASP.Net application hosted on Azure. I have added a .svc and some workflows that I want to use via WCF. To keep matters simple, my web app simply calls the service on localhost, so I have endpoints like these in web.config;
<client>
<endpoint address="http://localhost:8080/Router.svc/Case" binding="basicHttpBinding" contract="NewOrbit.ExVerifier.Model.Workflow.Case.ICaseWorkflow" name="Case" />
<endpoint address="http://localhost:8080/Workflow/Case/Case_default1.xamlx" binding="basicHttpBinding" contract="*" name="Case_default1" />
</client>
这工作我的本地机器就好了。问题是,我发布此天青时,在IIS中的网站没有得到一个绑定到本地主机,而不是绑定总是到服务器的实际IP地址。
它结束了在的applicationHost.config看起来像这样:
This works just fine on my local machine. The problem is that when I publish this to Azure, the Website in IIS does not get a binding to localhost, instead the bindings are always to the actual IP address of the server. It ends up looking like this in applicationHost.config:
<bindings>
<binding protocol="http" bindingInformation="10.61.90.44:80:" />
<binding protocol="https" bindingInformation="10.61.90.44:443:" />
<binding protocol="http" bindingInformation="10.61.90.44:8081:" />
</bindings>
所以,只要我的web应用程序试图调用(为此事或127.0.0.1)在本地主机上的服务,它立即将失败。
不用说,如果我RDP到服务器,并更改绑定那么一切都很好。
So, as soon as my web app tries to call the service on localhost (or 127.0.0.1 for that matter) it fails instantly. Needless to say, if I rdp on to the server and change the binding then all is fine.
的我发现真是奇怪的是,有吨的例子在那里,人们都在Azure上的本地主机访问WCF服务,让我想不通为什么会是这样。的我已经设置了osFamily 2,为了调试这个我已经启用了Web发布和远程桌面访问我的猜测,在理论上,可以搞搞。
What I find really odd is that there are tons of examples out there where people are accessing WCF services on localhost on Azure so I can't figure out why this is so. I have set the osFamily to 2 and in order to debug this I have enabled web publishing and remote desktop access which I guess, in theory, could mess things up.
我已经看过
- 我可以在我的code运行时重写终点地址来代替本地主机的实际地址或动态创建端点作为答案由Ron描述。不幸的是我使用WCF路由服务这样我就可以版本的工作流程。这意味着,我的code调用路由器端点和WCF路由器轮流使用呼叫在web.config中指定端点实际的服务/工作流程。我没有控制路由没有了,我想,写了一整套路由刚刚似乎是一个大量的工作时,我要的是调用本地主机的逻辑服务端点解决方案:)
- 切换到使用命名管道;可惜的是,它会导致一些奇怪的问题与工作流,可能是由于双面打印和我在一个最后期限,以便没有时间去的,在一分钟的底部。
推荐答案
好了,所以这是我如何解决它。恕我直言,这是一个黑客,但至少它的作品。
Okay, so this is how I solved it. IMHO it's a hack but at least it works.
基本上,我需要添加一个*的结合,这样我就可以在PowerShell中做到这一点。一般的配方是在这里:<一href=\"http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was-and-iis-on-windows-azure.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was-and-iis-on-windows-azure.aspx
Basically, I need to add a "*" binding, so I can do this in Powershell. The general recipe is here: http://blogs.msdn.com/b/tomholl/archive/2011/06/28/hosting-services-with-was-and-iis-on-windows-azure.aspx
这与添加命名管道的支持,但原理是一样的交易。我只是改变了PowerShell脚本为:
That deals with adding Named Pipes support, but the principle is the same. I just changed the Powershell script to:
import-module WebAdministration
# Set up a binding to 8080 for the services
Get-WebSite "*Web*" | Foreach-Object {
$site = $_;
$siteref = "IIS:/Sites/" + $site.Name;
New-ItemProperty $siteref -name bindings -value @{protocol="http";bindingInformation="*:8080:"}
}
这现在允许我使用 http://127.0.0.1:8080/service.svc访问我的服务。
This now allows me to use http://127.0.0.1:8080/service.svc to access my service.
的注意:您需要按照配方的其余部分设置高架执行上下文,并更改PowerShell的执行模式,所以不要按照它仔细的
这篇关于在Azure在本地主机上使用WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!