2013-01-06 64 views
0

我有一個具有2個Web角色(Azure網站項目和Azure WCF服務角色)的Azure項目。 WCF服務由Azure網站項目使用,並使用「添加服務引用」選項引用。該網站使用web.config中定義的URL連接到在本地開發/ Azure計算模擬器中正常工作的WCF服務。在我的本地開發機器中,當我運行該解決方案時,服務&網站將在具有URL「http://127.0.0.1:8080/v1.svc」和「http://127.0」的IIS Express中加載和執行。 0.1:81 /「。Azure(網站)Web角色項目中的Dyanmic WCF服務URL更新

但是,當我在Azure雲服務上發佈應用程序時,它分別爲網站和服務創建了單獨的機器/ VM /實例(因爲它們被認爲是兩個不同的角色)。

現在我的問題是,由於Azure在運行時爲實例指定了IP,應該如何動態更改(在網站的web.config中)URL並更新WCF服務以使網站能夠無縫地使用WCF服務?

欣賞你的時間。

謝謝, Karthik。

回答

-1

指定端點/端口在ServiceConfig文件服務:

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"> 
    <WebRole name="WCFServiceRole"> 
     … 
     <Endpoints> 
     <InputEndpoint name="HttpIn" protocol="http" port="8080" localPort="8080" /> 
     </Endpoints> 
    </WebRole> 
    <WebRole name="MyWebRole"> 
     … 
     <Endpoints> 
     <InputEndpoint name="HttpIn" protocol="http" port="80" localPort="80" /> 
     </Endpoints> 
    </WebRole> 
    … 
</ServiceDefinition> 

然後在你的web.config中,指定使用Azure的DNS和端口的WCF終結(即mywebrole.cloudapp.net:8080

欲瞭解更多信息,參考 - Guidance for Using WCF in Windows Azure

0

感謝您的答覆我嘗試瞭解決方案,但爲得到一個404錯誤,在我的情況下webrole名稱是「TimeSheetUI」,當我試圖訪問該服務。使用「timesheetui.cloudapp.net:8080」我t拋出404錯誤。 但是,如果我嘗試訪問它使用http://e214d16594be4e31abfbf0488b5d612b.cloudapp.net:8080/timesheetservices.svc它的作品。我希望我不需要添加任何CNAME條目與DNS等,使其工作。

但我嘗試編程選項來建立在運行時的URL與服務端點的類型選項設置爲「內部」。

var endpoints = RoleEnvironment.Roles["TimeSheetService"].Instances.Select(i => i.InstanceEndpoints["TimeSheetService.EndPoint"]).ToArray(); 
var r = new Random(); 
EndpointAddress endPointAddress = new EndpointAddress(String.Format("http://{0}/TimeSheetService.svc", endpoints[r.Next(endpoints.Count() - 1)].IPEndpoint)); 
var factory = new ChannelFactory<TimeSheetProxy.ITimeSheet>("BasicHttpBinding_ITimeSheet");var client = factory.CreateChannel(endPointAddress);TimeSheetUI.TimeSheetProxy.TimeSheet[] ts = client.DisplayTimeSheets(); 

上面的代碼工作正常,沒有問題。但不知道這是否是一種完美的方式!

找到上述解決方案@http://lab.studiopesec.com/azure-applications-101-part-ii/

相關問題