Learn About MCSD Microsoft .NET Skills
By Certification Magazine —
1 | 2 | 3 | 4 | 5 |
Protected Sub RenewPolicyCompleted(ByVal sender As Object, _
ByVal args As RenewPolicyCompletedEventArgs)
'process the results
End Sub
This code uses the RenewPolicyCompleted event and invokes the RenewPolicyAsync method for asynchronous programming. The code then invokes the Transfer method on the Server object to transfer processing to the next page while waiting for the asynchronous result.
In the .NET Framework 2.0, Web methods can be called asynchronously using the proxy method XXXAsync and the XXXCompleted event. For example, if the synchronous method was named GetData, then the asynchronous method would be GetDataAsync and the associated event would be GetDataCompleted.
The XXXAsync method takes the same arguments as its synchronous version, and the event handler assigned to the XXXCompleted event will execute once the asynchronous invocation is complete. The Result property of the XXXCompletedEventArgs parameter is used to access the return results.
In the .NET Framework 1.0 and above, Web methods can also be called asynchronously by clients using the proxy class methods BeginXXX and EndXXX. For example, if the synchronous method was named GetData, then the asynchronous methods would be BeginGetData and EndGetData. The BeginXXX method accepts the same arguments as the synchronous version, as well as two other arguments: an AsyncCallback delegate to invoke when complete and an argument of type object for passing data to the AsyncCallback delegate.
The BeginXXX method returns an instance of type IAsyncResult to monitor the asynchronous invocation. This instance is used by the EndXXX method to retrieve the results. Based on when and how the EndXXX method is invoked, the following techniques can be implemented:
• Waiting: In this technique, you use the AsyncWaitHandle property of the IAsyncResult object to wait for the WaitHandle instance to receive a complete signal and then invoke the EndXXX method. This will block the executing thread until the WaitHandle condition is satisfied (more on the WaitHandle class below).
• Polling: In this technique, you can poll the IAsyncResult object by checking its IsCompleted property. When the value of the IsCompleted property is True, the EndXXX method can be invoked. This will block the executing thread only while checking the IsCompleted property.
• Callback: In this technique, you pass an AsyncCallback delegate to the BeginXXX method. The callback delegate will execute the specified method on a separate thread when the asynchronous invocation is complete. The method will then invoke the EndXXX method and retrieve the results.
You should not use the codes that invoke the synchronous RenewPolicy Web method because these codes do not invoke the RenewPolicy method asynchronously. It does not matter whether the Server.Transfer or Response.Redirect method is invoked because the RenewPolicy method is not invoked asynchronously, and in both cases, the next page will display only after being blocked by the synchronous operation. You should invoke the BeginRenewPolicy or RenewPolicyAsync methods to perform an asynchronous operation.
You should not use the code that invokes the WaitOne method because this will block the asynchronous operation until it completes. You should not use the WaitHandle class in this scenario because no waiting is required.
The WaitHandle class enables classes to implement a signaling mechanism for exclusive access to a shared resource. The WaitHandle class has three important methods to block execution based on thread signals: WaitAll, WaitOne and WaitAny.
• WaitAll: This method accepts an array of WaitHandle instances and blocks execution only when all the elements in the array have received a complete signal. This is a class member.
• WaitOne: This method returns control only when the current WaitHandle instance receives a complete signal. This is an instance member.
• WaitAny: This method accepts an array of WaitHandle instances and blocks execution until one of the elements in the array has received a complete signal. It returns the element index that completed. This is a class member.
References:
MSDN2 Library > Development Tools and Languages > Visual Studio > Windows-based Applications, Components, and Services > XML Web Services in Managed Code > Accessing XML Web Services in Managed Code > How to: Access an XML Web Service Asynchronously in Managed Code
MSDN2 Library > Development Tools and Languages > Visual Studio > Windows-based Applications, Components, and Services > XML Web Services in Managed Code > XML Web Services Created Using ASP.NET and XML Web Service Clients > Building XML Web Service Clients > Communicating with XML Web Services Asynchronously
MSDN2 Library, Search, ".NET Development," ".Net Framework SDK," "Class Library Reference," "System.Threading," "WaitHandle Class," "WaitHandle Methods."
Objective: Implement Web-services enhancements (WSE) 3.0.
Sub-objective: Enable WSE in client and server applications.
Single answer, multiple-choice
As an enterprise application developer, you want to enable WSE 3.0 on an existing Web service. This Web service has never been WSE enabled. What should you do?
A. Add a reference to the Microsoft.Web.Services3 assembly and the following to the web.config:
<configSections>
<section name="microsoft.web.services3"
type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</configSections>
B. Add a reference to the Microsoft.Web.Services3 assembly and the following to the web.config:
<system.web>
<webServices>
<soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</webService>
</system.web>
C. Add a reference to the Microsoft.Web.Services3 assembly and the following to the web.config:
<soapExtensionTypes>
<add type="Microsoft.Web.Services3.WebServicesExtension,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" priority="1" group="0" />
</soapExtensionTypes>
D. Add a reference to the Microsoft.Web.Services3 assembly and have the Web service inherit from the WebServicesProtocol class.
Answer:
B. Add a reference to the Microsoft.Web.Services3 assembly and the following to the web.config:
<system.web>
<webServices>
<soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</webService>
</system.web>
Tutorial:
To enable WSE 3.0 for a Web service, you should add a reference to the Microsoft.Web.Services3 assembly and the following to the web.config:




