为什么要使用beginInvoke和DebuggerStepThroughAttribute等属性
当我查看一些代码示例时,我注意到以下属性,我不明白如何使用这些属性。这个类似乎是从 xsd 生成的。
[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.属性中的return是做什么的?
3.FlightHistoryGetRecordsResponse
方法使用了哪些参数,为什么返回this.BeginInvoke
?
While I was going through some code sample, I noticed the following attributes which I do not understand how used.This classes seems to be generated from xsd.
[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")]
Also could not understand the following methods:
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]));
}
So I have the following questions:
1. What does each attribute do.
2.What is the return doing in attributes?
3.What are the parameters used in FlightHistoryGetRecordsResponse
method and why is it returning this.BeginInvoke
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1a:DebuggerStepThough 属性指示当断点被设置时hit 并且编码器正在单步执行代码,调试器将跳过此方法,而不是在每一行暂停。
1b:DesignerCategory 属性指示类的分组如果/当它出现在设计时控件中,例如 Visual Studio 中的属性网格中。
1c: WebServiceBinding 属性附加名称和代表 Web 服务的类的命名空间。
重要的是要理解属性不“做”任何事情,它们只包含元数据,并且由代码的其他部分决定如何处理该元数据。
2:属性之前的 return 语句表明该属性适用于从方法返回的值,而不适用于方法本身。同样,您可以将属性应用于方法参数。在本例中,该属性描述了如何将返回值序列化为 XML。
3:这与常规请求/响应 Web 服务调用类似,但已修改为异步。 AsyncCallback 是异步操作完成时应调用的方法,返回值是 AsyncResult,可用于从代码的其他部分检查正在运行的操作。这是异步方法调用的旧模式,您不再发现这种代码了。 请参阅 MSDN 上的异步模式...
1a: The DebuggerStepThough attribute indicates that when a breakpoint is hit and the coder is stepping through the code, the debugger will skip over this method rather than pausing on each line.
1b: The DesignerCategory attribute indicates the grouping for the class if/when it appears in design time controls such as the property grid in visual studio.
1c: The WebServiceBinding attribute attaches the name and the namespace to a class which represents a web service.
It's important to understand that attributes don't "do" anything, they just contain meta-data and it's up to other parts of code what to do with that meta-data.
2: The return statement before the attribute indicates that the attribute applies to the value being returned from the method, not to the method itself. Similarly you can apply attributes to the method parameters. In this case the attribute is describing how the return value should be serialized into XML.
3: This is similar to a regular request/response web service call, but it has been modified to be asynchronous. The AsyncCallback is a method that should be called when the asynchronous operation has compelted, and the return value is an AsyncResult which can be used to inspect the running operation from other parts of code. This is the old pattern of asynchronous method calls and you don't find this kind of code much anymore. See Async Pattern on MSDN...
Attribute 中的 return 将属性分配给方法的返回类型,类似于 AssemblyInfo.cs 中的 assembly:Someattribute。
BeginInvoke 异步调用方法并返回一个对象,该对象为您提供该调用的状态信息以及获取最终结果的方法。
有关所有属性的描述,我建议您阅读 MSDN 文档并提出具体问题。
The return in the Attribute assigns the attribute to the return type of the method, similar to assembly:Someattribute in the AssemblyInfo.cs.
BeginInvoke calls a method asynchronously and returns an object that gives you status information of that call and a way to get the final result.
For a description of all the attributes I suggest you read the MSDN documentation and ask specific questions.