自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

在Windows Azure中實(shí)現(xiàn)和調(diào)試一個(gè)WCF服務(wù)(中)

原創(chuàng)
云計(jì)算
為了把在Windows Azure中運(yùn)行的,使用強(qiáng)大的WCF框架的服務(wù)暴露出來,Windows Azure提供了一個(gè)WCF角色。無論在哪個(gè)框架和平臺(tái)上構(gòu)建復(fù)雜的,具有高度可擴(kuò)展性的系統(tǒng),通過它們的功能進(jìn)行邏輯分組,針對(duì)那些分組來抽象代碼,并且分別執(zhí)行它們,都是一種簡單而高效的擴(kuò)展性策略。

本文接《在Windows Azure中實(shí)現(xiàn)和調(diào)試一個(gè)WCF服務(wù)(上)》和《在Windows Azure中實(shí)現(xiàn)和調(diào)試一個(gè)WCF服務(wù)(下)》

做一些改動(dòng)

如果你跳轉(zhuǎn)到了***的總結(jié)文件上,那么歡迎回來。

現(xiàn)在我們會(huì)對(duì)這個(gè)基礎(chǔ)項(xiàng)目做一些改動(dòng),以便于我們可以告訴大家,如何擴(kuò)展這個(gè)解決方案的,如何中斷它,以及如何找出它中斷的原因。

首先,我會(huì)給這個(gè)服務(wù)添加一個(gè)新的方法,以便于我們可以看到如何開始擴(kuò)展這個(gè)服務(wù)。定位到“IService1”接口,然后添加下面這些代碼:

[OperationContract]       
float Divide(float dividend, float divisor);

現(xiàn)在,在這個(gè)接口上,我們擁有了一個(gè)新方法,我們必須要實(shí)現(xiàn)他。打開“Service1.svc.cs”,然后添加下面這些代碼:

public float Divide(float dividend, float divisor) 

{

             if (divisor == 0F)

            {

                        throw new DivideByZeroException();    

            }

            return dividend / divisor;
}

現(xiàn)在,我們擁有了一個(gè)新方法,我們終于可以讓一些事情失敗了!

在Visual Studio中運(yùn)行它(或者debug),然后你會(huì)看到下面這個(gè)頁面:

雖然這可以保證這個(gè)WCF服務(wù)是可以正常工作的,但是我們無法使用瀏覽器來調(diào)用它。取而代之,我們會(huì)求助于一個(gè)簡單的,可以和WCF進(jìn)行通信的Worker角色客戶端。

首先,向這個(gè)解決方案中添加一個(gè)新的項(xiàng)目,在圖中那個(gè)節(jié)點(diǎn)上右擊:

然后,這個(gè)Worker角色需要?jiǎng)?chuàng)建一個(gè)可以和我們前面創(chuàng)建的WCF服務(wù)進(jìn)行通信的客戶端。要完成這個(gè)工作,需要在“References”上右擊,然后添加一個(gè)“Service Reference”:

然后,它可以讓我們選擇是添加一個(gè)現(xiàn)有的服務(wù),還是添加是一個(gè)解決方案中的服務(wù)。目前來說,我們使用解決方案內(nèi)部的WCF服務(wù)。

                try

              {

                    for (int i = 100; i >= 0; i--)

                    {

                        Trace.WriteLine(service1.Divide(100F, (float)i));

                    }

                }

                catch (Exception ex)

                {

                    Trace.TraceError(ex.ToString());

                }

實(shí)際上,綁定到一個(gè)現(xiàn)有Azure實(shí)例會(huì)更加容易一些——這是因?yàn)樵诒镜亟壎愕慕鉀Q方案可能會(huì)獲得錯(cuò)誤的端口號(hào)(本地的IIS端口而不是Windows Azure Emulator運(yùn)行的端口——如果你沒有小心地關(guān)閉掉你的調(diào)試會(huì)話,那么這個(gè)Windows Azure Emulator端口可能會(huì)改變)。如下圖所示,當(dāng)查找一個(gè)本地解決方案的時(shí)候,獲得了一個(gè)錯(cuò)誤的端口號(hào):
 

為了糾正這個(gè)問題,可以用你為WCF角色手工配置的端口替換掉這個(gè)端口號(hào)。你可以在“ServiceDefinition.csdef”文件中配置這個(gè)端口號(hào),或者也可以通過在WCF角色上右擊,然后打開它的屬性頁的方式來達(dá)到這個(gè)目的,在這個(gè)例子中,我就是這樣做的:

注意,接下來你必須修改<client><endpoint>的地址屬性,讓它的端口號(hào)和上面配置的端口號(hào)相匹配。任何時(shí)候,Compute Emulator都不會(huì)正確地關(guān)閉,你必須重啟它們,以確保它們是匹配的,否則,你會(huì)得到一個(gè)異常,告訴你在WCF客戶端配置中指定的端口沒有端點(diǎn)(endpoint)在監(jiān)聽。

為了成功地調(diào)用這個(gè)WCF服務(wù),我們需要給Worker角色添加一些代碼。我們簡單地從100迭代到0,以100F作為參數(shù)調(diào)用Divide方法,***,在迭代到0的時(shí)候,我們的代碼會(huì)故意地拋出一個(gè)“DivideByZeroException”異常。

                try

                {

                    for (int i = 100; i >= 0; i--)

                    {

                        Trace.WriteLine(service1.Divide(100F, (float)i));

                    }

                }

                catch (Exception ex)

                {

                    Trace.TraceError(ex.ToString());

                }

客戶端的WCF通信輸出會(huì)收到一個(gè)WCF異常,但是不會(huì)包含一些細(xì)節(jié)。

snip...

10

11.11111

12.5

14.28571

16.66667

20

25

33.33333

50

100

[WaWorkerHost.exe] System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Server stack trace:

at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)

at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)

at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

at WcfClientRole.AzureWcfBasic.IService1.Divide(Single dividend, Single divisor)

at WcfClientRole.AzureWcfBasic.Service1Client.Divide(Single dividend, Single divisor) in c:\dev\Blog\WCFBasic\WcfClientRole\Service References\AzureWcfBasic\Reference.cs:line 119

at WcfClientRole.WorkerRole.Run() in c:\dev\Blog\WCFBasic\WcfClientRole\WorkerRole.cs:line 31

從理論上來說,我們可以打開異常信息的細(xì)節(jié),但是這不是一種安全的做法。為了接下來可以調(diào)試這個(gè)信息,我們需要看一看剛才配置過的Windows Azure Diagnostics。

本文接《在Windows Azure中實(shí)現(xiàn)和調(diào)試一個(gè)WCF服務(wù)(上)》和《在Windows Azure中實(shí)現(xiàn)和調(diào)試一個(gè)WCF服務(wù)(下)》

原文名:Implementing and Debugging a WCF Service in Windows Azure 作者:Andy

【本文乃51CTO精選譯文,轉(zhuǎn)載請(qǐng)標(biāo)明出處!】
 

【編輯推薦】 

  1. 微軟公布云計(jì)算平臺(tái)Azure收費(fèi)模式細(xì)節(jié)
  2. 云計(jì)算意在長遠(yuǎn),微軟云計(jì)算服務(wù)Windows Azure已經(jīng)啟用
  3. 技術(shù)透析:Windows Azure Platform框架與組成
  4. 微軟Windows Azure Platform技術(shù)解析
  5. 走近微軟云:SQL Server到Azure數(shù)據(jù)同步
  6. 當(dāng)微軟Azure遭遇亞馬遜EC2:五大關(guān)鍵區(qū)別
  7. Windows Azure云計(jì)算平臺(tái)新增五大功能
  8. 云計(jì)算前途光明 Azure用戶數(shù)突破31000
  9. 如何把應(yīng)用程序部署到Windows Azure中

 

 

責(zé)任編輯:王勇 來源: 來源:51CTO
相關(guān)推薦

2011-03-15 16:12:00

Windows AzuWCF

2011-03-15 15:43:39

Windows AzuWCF

2010-11-25 10:05:22

Visual StudSilverlightWCF

2011-03-22 09:45:56

Windows AzuSilverlight

2011-03-22 10:03:55

Windows AzuSilverlight

2011-03-24 13:02:35

WCF服務(wù)角色Azure

2011-03-10 10:45:47

Azure“Hello Worl

2009-06-25 11:18:20

Silverlight

2020-12-16 14:29:40

終端開發(fā)shell

2022-05-22 13:55:30

Go 語言

2021-01-04 09:12:31

集合變量

2013-05-24 08:56:46

Windows Azu微軟云計(jì)算平臺(tái)Windows Ser

2009-12-21 14:58:57

WCF用戶密碼認(rèn)證

2009-03-30 15:52:24

Windows Emb

2012-04-20 10:05:16

WCF

2011-03-14 15:10:10

AzureFacebook

2013-03-27 09:55:17

微軟Windows AzuHadoop

2010-02-25 17:22:39

WCF服務(wù)行為

2019-11-27 13:50:35

bauh軟件包應(yīng)用

2015-08-06 13:44:21

swiftcocoapods
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)