Learn About MCSD Microsoft .NET Skills
By Certification Magazine —
1 | 2 | 3 | 4 | 5 |
Tutorial:
You should add the following code to the client application configuration file to consume the remote ProductService object:
<system.runtime.remoting>
<application>
<client>
<wellknown
type="ProductService, Product"
url="tcp://TestMachine:8800/ProductService" />
</client>
</application>
</system.runtime.remoting>
This code applies the client and wellknown elements for server-activated object remote types in a client application and specifies the remote type and remote URL as the TCP port number 8800 on the TestMachine server.
In .NET remoting, remote types can be classified according to activation:
• Server-activated Object (SAO): SAO remote types are created and controlled by the server application. The remote object is created on the server, and the server controls the lifetime of the remote object. SAO remote types, also referred to as "well-known" remote types, have two object modes: SingleCall and Singleton.
SingleCall SAO remote types are instantiated or activated every time a method is invoked. The remote object does not maintain state between method invocations. Singleton SAO remote types remain in memory for a specified time and are not deactivated between method invocations.
In Singleton mode, the client invokes methods on the same remote object, whereas in SingleCall the client invokes a method on a different remote object.
• Client-activated Object (CAO): CAO remote types are created and controlled by the client application. The remote object is created on the server, but the client makes the creation request and controls the lifetime of the remote object.
You must register the remote types either programmatically or through configuration files on both the server and client. A remote type registration is included in a remoting application. The remoting application must define a channel (IPC, TCP or HTTP) and port for communication and a registration entry in the application for each remote type.
On the client application, the client element is used for client registration. Either the wellknown or activated element should be specified whether the remote object is SAO or CAO. Both of these elements specify the displayName, type and url attributes for contacting the remote object in the server application.
On the server application, the service element is used for server registration. When registering an SAO, the wellknown element specifies the mode, type and objectUri attributes. When registering a CAO, the activated element specifies only the type attribute.
You should not use the codes that specify the service element because these codes are used for server registration in the server application of remote type, not client registration. You should specify the client element in the client application configuration file.
You should not use the codes that specify the mode and objectUri attributes, but do not specify the url attribute for the wellknown element because this client registration only requires the type and url attribute. Server registration requires the other attributes in the wellknown element. If used, an exception will be thrown.
Reference:
MSDN2 Library > Development Tools and Languages > Visual Studio > .NET Framework Programming in Visual Studio > .NET Framework Core Development > Configuration > Registering Remote Objects Using Configuration Files > Client-Side Registration
Objective: Implement asynchronous calls and remoting events.
Sub-objective: Call Web methods asynchronously.
Single answer, multiple-choice
You are an enterprise application developer at Globecomm Corp. You are developing an ASP.NET 2.0 Web application for customers to renew their existing insurance policies. The Web application consumes a Web service named InsuranceSolutionService.
The InsuranceSolutionService Web service is defined as follows:
Public Class InsuranceSolutionService
Inherits WebService
<WebMethod()> _
Public Function RenewPolicy(ByVal number As Integer, _
ByVal amount As Single, ByVal duration As Integer) As Boolean
'Implementation code
End Function
End Class
One of the Web pages, RenewPolicy.aspx, has a button for customers to renew their existing policies. When a user clicks the RenewPolicyButton Web control in the client Web application, the RenewPolicy method should be invoked before displaying the next Web page to the user. You enable the asynchronous operations on the page.
The RenewPolicy method takes a significant amount of time to complete execution. While the RenewPolicy method is executing, the user should be taken to the next page in the Web application. Which code should you use to invoke the RenewPolicy Web method?
A. Protected Sub RenewPolicyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim proxy As New InsuranceSolutionService()
proxy.RenewPolicy(policyNumber, amount, 365)
Server.Transfer("RenewalProcess.aspx")
End Sub
B. Protected Sub RenewPolicyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim proxy As New InsuranceSolutionService()
AddHandler proxy.RenewPolicyCompleted, AddressOf RenewPolicyCompleted
proxy.RenewPolicyAsync(policyNumber, amount, 365)
Server.Transfer("RenewalProcess.aspx")
End Sub
Protected Sub RenewPolicyCompleted(ByVal sender As Object, _
ByVal args As RenewPolicyCompletedEventArgs)
'process the results
End Sub
C. Protected Sub RenewPolicyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim proxy As New InsuranceSolutionService()
Dim aResult As IAsyncResult = _
proxy.BeginRenewPolicy(policyNumber, amount, 365, Nothing, Nothing)
aResult.AsyncWaitHandle.WaitOne()
proxy.EndRenewPolicy(aResult)
Server.Transfer("RenewalProcess.aspx")
End Sub
D. Protected Sub RenewPolicyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim proxy As New InsuranceSolutionService()
proxy.RenewPolicy( policyNumber, amount, 365 )
Response.Redirect( "RenewalProcess.aspx" )
End Sub
Answer:
B. Protected Sub RenewPolicyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim proxy As New InsuranceSolutionService()
AddHandler proxy.RenewPolicyCompleted, AddressOf RenewPolicyCompleted
proxy.RenewPolicyAsync(policyNumber, amount, 365)
Server.Transfer("RenewalProcess.aspx")
End Sub
Protected Sub RenewPolicyCompleted(ByVal sender As Object, _
ByVal args As RenewPolicyCompletedEventArgs)
'process the results
End Sub
Tutorial:
You should use the following code to invoke the RenewPolicy method asynchronously and take the user to the next page in the meantime:
Protected Sub RenewPolicyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim proxy As New InsuranceSolutionService()
AddHandler proxy.RenewPolicyCompleted, AddressOf RenewPolicyCompleted
proxy.RenewPolicyAsync(policyNumber, amount, 365)
Server.Transfer("RenewalProcess.aspx")
End Sub




