2011-12-29 74 views
0

雖然我正在瀏覽一些代碼示例,但我注意到以下屬性,我不明白它是如何使用的。這些類似乎是從xsd生成的。爲什麼要使用beginInvoke和DebuggerStepThroughAttribute和其他屬性

[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Web.Services.WebServiceBindingAttribute(Name="FlightHistoryGetRecordsSOAPBinding", Namespace="http://www.pathfinder-xml.com/FlightHistoryService.wsdl")] 


[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)] 
[return: System.Xml.Serialization.XmlElementAttribute("FlightHistoryGetRecordsResponse", Namespace="http://pathfinder-xml/FlightHistoryService.xsd")] 

也弄不明白下面的方法:

public System.IAsyncResult BeginFlightHistoryGetRecordsOperation(FlightHistoryGetRecordsRequest FlightHistoryGetRecordsRequest, System.AsyncCallback callback, object asyncState) { 
     return this.BeginInvoke("FlightHistoryGetRecordsOperation", new object[] { 
        FlightHistoryGetRecordsRequest}, callback, asyncState); 
    } 

    /// <remarks/> 
    public FlightHistoryGetRecordsResponse EndFlightHistoryGetRecordsOperation(System.IAsyncResult asyncResult) { 
     object[] results = this.EndInvoke(asyncResult); 
     return ((FlightHistoryGetRecordsResponse)(results[0])); 
    } 

所以,我有以下問題:
1.什麼是每個屬性做。
2.回報在屬性中做什麼?
3. FlightHistoryGetRecordsResponse方法中使用的參數是什麼以及爲什麼返回this.BeginInvoke

回答

3

1a:DebuggerStepThough屬性指示當一個斷點被命中並且編碼器遍歷代碼時,調試器將跳過此方法而不是在每一行上暫停。

1b:DesignerCategory屬性表示該類在出現在設計時控件(如Visual Studio中的屬性網格)中時的分組。

1c:WebServiceBinding屬性將名稱和名稱空間附加到表示Web服務的類。

重要的是要明白,屬性不「做」任何事情,它們只包含元數據,它取決於代碼的其他部分如何處理元數據。

2:屬性前的return語句指示該屬性適用於從方法返回的值,而不是方法本身。同樣,您可以將屬性應用於方法參數。在這種情況下,該屬性描述瞭如何將返回值序列化爲XML。

3:這與常規的請求/響應Web服務調用類似,但它已被修改爲異步。 AsyncCallback是在異步操作強制執行時應該調用的方法,並且返回值是一個AsyncResult,可用於從其他代碼部分檢查正在運行的操作。這是異步方法調用的舊模式,您再也找不到這種類型的代碼了。 See Async Pattern on MSDN...

0

屬性中的返回將該屬性分配給該方法的返回類型,類似於Assembly:AssemblyInfo.cs中的Someattribute。

BeginInvoke異步調用方法並返回一個對象,該對象爲您提供該調用的狀態信息並獲得最終結果。

有關所有屬性的描述,我建議您閱讀MSDN文檔並提出具體問題。

相關問題