Apply Your Knowledge
Exercises
3.1 - Using HTTP Channels with Binary Formatters
As I discussed in the chapter, the default formatter for an HTTP channel is SOAP and for a TCP channel is Binary. The formatters are used for serializing and deserializing messages in the specified encoding.
The chapter has made use of these default formatters in the examples. In this exercise, you'll learn how to configure a channel to use a formatter different from the default one.
In particular, I'll demonstrate how to use the binary formatter with the HTTP channel. This combination is especially useful when you want to optimize the performance of a remote object that is hosted on IIS. However, you should note that binary format is proprietary to the .NET Framework.
Estimated Time: 30 minutes.
-
Launch Visual Studio .NET. Select File, New, Blank Solution, and name the new solution 310C03Exercises. Click OK.
-
Add a new Empty Web Project named Exercise3-1_Server to the solution.
-
Add references to StepByStep3-9.dll (the interface assembly containing IDbConnect) and StepByStep3-10.dll (the remotable object, DbConnect) from the 310C03 solution. You'll need to use the Browse button in the Add Reference dialog box to locate these libraries.
-
Add a new Web Configuration File to the project. Open the web.config file and add the following <system.runtime.remoting> element inside the <configuration> element:
-
IIS is now hosting the StepByStep3-10.DbConnect, the remotable class, as a server activated object using the Singleton activation mode.
-
Add a new Visual Basic .NET Windows Application named Exercise3-1_Client to the solution.
-
Add a reference to StepByStep3_9.dll (the interface assembly containing IDbConnect).
-
In the Solution Explorer, right-click project Exercise3_1_Client and select Add, Add New Item from the context menu. Add an Item named Exercise3-1_Client.exe.config based on the XML File Template.
-
Open the Exercise3_1_Client.exe.config file and modify it to contain the following code:
-
In the Solution Explorer, select the project and click the Show All Files button in the toolbar. Move the Exercise3-1_Client.exe.config file from the project folder to the bin folder under the project, where the Exercise3-1_Client.exe file will be created when the project is compiled.
-
In the Solution Explorer, delete the default Form1.vb. Add a new form named DbConnectClient.vb and set it as the startup object for the project.
-
Place two GroupBox controls (grpQuery and grpResults), a TextBox control (txtQuery), a Button control (btnExecute), and a DataGrid control (dgResults) on the form. Set the Multiline property of txtQuery to True. Refer to Figure 3.5 for the design of this form.
-
Add the following directives:
-
Add the following code directly after the Windows Form designer generated code:
-
Double-click the form and add the following code in the Load event handler:
-
Double-click the Button control and add the following code in the Click event handler:
-
Build the project. Set the Exercise3-1_Client, the remoting client, as the startup project. Select Debug, Start Without Debugging to run the project. Enter a query in the text box and click the button. The code invokes a method on the remote object. The remote object is serialized and deserialized in binary format and is transported over the HTTP protocol. The code binds the results from the remote method to the DataGrid control.
<configuration> <system.runtime.remoting> <application> <service> <!-- Set the activation mode, remotable object and its URL --> <wellknown mode="Singleton" type="StepByStep3_10.DbConnect, StepByStep3_10" objectUri= "DbConnect.rem" /> </service> </application> </system.runtime.remoting> ... </configuration>
<configuration> <system.runtime.remoting> <application> <channels> <channel ref="http"> <serverProviders> <formatter ref = "binary" /> </serverProviders> </channel> </channels> </application> </system.runtime.remoting> </configuration>
Imports System.Runtime.Remoting Imports StepByStep3_9
' Declare a Remote object Dim dbc As IDbConnect
Private Sub DbConnectClient_Load( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load ' Load remoting configuration RemotingConfiguration.Configure( _ "Exercise3-1_Client.exe.config") ' Instantiate the remote class dbc = CType( _ Activator.GetObject( _ GetType(IDbConnect), _ "http://localhost/Exercise3-1_Server/DbConnect.rem"), IDbConnect) End Sub
Private Sub btnExecute_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnExecute.Click Try ' Invoke a method on ' the remote object Me.dgResults.DataSource = _ dbc.ExecuteQuery(Me.txtQuery.Text) dgResults.DataMember = "Results" Catch ex As Exception MessageBox.Show(ex.Message, _ "Query Execution Error") End Try End Sub
Note that you should always configure the client to use the binary formatter when configuring the server (IIS) to use the binary formatter. You can specify the desired formatter for the client and need not specify the channel formatter for the server. The formatter requested by the client will be used to format data by the server for that client.
3.2 - Dynamically Publishing a WellKnown Object
WellKnown objects cannot be invoked from a client with a non-default constructor. You can create an object using any constructor you wish, initialize it anyway you wish, and then make it available to clients.
Use RemotingServices.Marshal() to publish an existing object instance.
Estimated Time: 30 minutes.
-
Add a new Visual Basic .NET Console Application named Exercise3-2_Server to the solution.
-
Add references to .NET assembly System.Runtime.Remoting, the StepByStep3-9.dll (the interface assembly containing IDbConnect), and StepByStep3-10.dll (the remotable object, DbConnect).
-
In the Solution Explorer, rename the default Module1.vb to DbConnectServer.vb. Open the file and change the name of the module to DbConnectServer in the module declaration. Set this new module to be the Startup object for the project.
-
Add the following directives:
-
Add the following code in the Main() method:
-
Build the project. This step creates a remoting server that creates the remotable object StepByStep3_10.DbConnect and is capable of marshalling the remote object across application boundaries.
-
Add a new Visual Basic .NET Windows Application named Exercise3-2_Client to the solution.
-
Add references to the .NET assembly System.Runtime.Remoting, and the project StepByStep3-9 (the interface assembly).
-
In the Solution Explorer, delete the default Form1.vb. Add a new form named DbConnectClient.vb and set it as the startup object for the project.
-
Add the following directives:
-
Place three GroupBox controls (grpDatabases, grpQuery and grpResults), a ComboBox control (cboDatabases), a TextBox control (txtQuery), a Button control (btnExecute), and a DataGrid control (dgResults) on the form. Set the DropDownStyle to DropDownList.
-
Select the Items property of the cboDatabases control in the Properties window and click on the (...) button. This opens the String Collection Editor dialog box. Enter the following names of databases in the editor:
Northwind Pubs
Click OK to add the databases to the Items collection of the cboDatabases control.
-
Add the following code directly after the Windows Form designer generated code:
-
Double-click the form and add the following code in the Load event handler:
-
Double-click the cboDatabases control and add the following code in the SelectedIndexChanged event handler:
-
Double-click the btnExecute control and add the following code in the Click event handler:
-
Build the project. You now have a remoting client ready to use.
-
Set the Exercise3-2_Server, the CAO remoting server, as the startup project. Select Debug, Start Without Debugging to run the project. You should see a command window displaying a message that the server is started in the Singleton mode. You should also see messages that the remote object is already created.
-
Now, set Exercise3_2_Client, the remoting client, as the startup project. Select Debug, Start Without Debugging to run the project. Select a desired database from the combo box, enter a query in the text box, and click the button. The code invokes a method on the remote object that is already created on the server. The code binds the results from the remote method to the DataGrid control.
-
Now, again select Debug, Start Without Debugging to run one more instance of the remoting client. Select a different database from the combo box, enter a query in the text box, and click the button. You should see that the second instance of the client fetches the data from the selected database.
Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting. _ Channels.Tcp Imports StepByStep3_10
Sub Main() ' Create and Register a ' TCP server channel ' that listens on port Dim channel As TcpServerChannel = _ New TcpServerChannel(1234) ChannelServices.RegisterChannel( _ channel) ' Create the remotable ' object here itself ' Call the RemotingServices.Marshal() ' method ' to marshal (serialize) ' the created remotable ' object to transfer the ' object beyond application ' boundaries with the specified uri Dim dbcPubs As DbConnect = _ New DbConnect("Pubs") RemotingServices.Marshal( _ dbcPubs, "Pubs.uri") Dim dbcNorthwind As DbConnect = _ New DbConnect("Northwind") RemotingServices.Marshal( _ dbcNorthwind, "Northwind.uri") Console.WriteLine( _ "Started server in the " & _ "Singleton mode") Console.WriteLine( _ "Press <ENTER> to terminate " & _ "server...") Console.ReadLine() End Sub
Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting. _ Channels.Tcp Imports StepByStep3_9
' Declare a Remote object Dim dbc As IDbConnect
Private Sub DbConnectClient_Load( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load ' Register a TCP client channel Dim channel As TcpClientChannel = _ New TcpClientChannel() ChannelServices.RegisterChannel( _ channel) cboDatabases.SelectedIndex = End Sub
Private Sub _ cboDatabases_SelectedIndexChanged( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles cboDatabases.SelectedIndexChanged Select Case cboDatabases. _ SelectedItem.ToString() Case "Pubs" ' Instantiate the remote class dbc = CType( _ Activator.GetObject( _ GetType(IDbConnect), _ "tcp://localhost:1234/Pubs.uri"), IDbConnect) Case "Northwind" ' Instantiate the remote class dbc = CType( _ Activator.GetObject( _ GetType(IDbConnect), _ "tcp://localhost:1234/Northwind.uri"), _ IDbConnect) End Select End Sub
Private Sub btnExecute_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnExecute.Click Try ' Invoke a method on ' the remote object Me.dgResults.DataSource = _ dbc.ExecuteQuery(Me.txtQuery.Text) dgResults.DataMember = "Results" Catch ex As Exception MessageBox.Show(ex.Message, _ "Query Execution Error") End Try End Sub
Review Questions
What is an application domain? How does the CLR manage an application domain?
What are MBR objects? What are their advantages?
What is a channel? What are the different types of channels provided by the .NET Framework?
What are the advantages and disadvantanges of the Binary and SOAP formatters?
What are the two modes to create Server-Activated objects?
When should you choose to create a Client-Activated object?
What is the benefit of using declarative configuration over programmatic configuration?
What are the two methods of the Activator class that allow you to create instances of remote objects?
What are the advantages of using IIS server as an activation agent?
What should you do while creating a remotable class so that its methods can be called asynchronously?
Exam Questions
You are designing a distributed application that hosts a remote object. You want only the authorized client application to be capable of activating the remote object. You want to write the application with a minimum amount of code. Which of the following channels enables you to achieve this objective? (Select two choices.)
HttpChannel
HttpServerChannel
TcpChannel
TcpServerChannel
You are designing a company-wide order processing system. This application is hosted on a server in the company's headquarters in Redmond, WA and is accessed by 1500 franchise locations throughout the world. The application specification mentions that the franchisees should be able to access the order-processing system even through the firewalls. A large number of franchisees access the application over a slow connection, and your objective is to maximize the performance of the application. Which of the following channel and formatter combinations would you choose in this scenario?
Use a TCP channel with a binary formatter
Use a TCP channel with a SOAP formatter
Use an HTTP channel with a binary formatter
Use an HTTP channel with a SOAP formatter
You are designing a distributed application for a large automotive company. The application allows the part suppliers across the globe to collect the latest design specifications for a part. The application is heavily accessed by the suppliers. For greater scalability, you are required to design the application so that it can be deployed in a load-balanced environment. How should you host the remotable object in this scenario?
As a server-activated object in SingleCall activation mode
As a server-activated object in Singleton activation mode
As a client-activated object using the HTTP channel
As a client-activated object using the SOAP formatter
You have been hired by Great Widgets Inc. to create an application that allows their supplier to access the purchase order information in real time. You create the required classes that can be activated remotely by the suppliers and package them into a file named gwpoinfo.dll. You plan to host this file using IIS as the remoting host. Your goal is that after the application has been deployed, there should be minimal steps involved to change the remoting configuration for this application. Also, any configuration changes made to the purchase order information system should not affect any other applications running on that server. Which of the following files would you choose to configure remoting for the purchase order information system?
gwpoinfo.dll
web.config
global.asax
machine.config
You have designed a remotable class named ProductDesign. You now want to register this class with the remoting system in such a way that the client program should be able to remotely instantiate objects of this class and invoke methods on it. You want there to be only one instance of this class on the server irrespective of the number of clients connected to it. Which of the following code snippets fulfills your requirement?
-
RemotingConfiguration. _ RegisterWellKnownServiceType( _ GetType(ProductDesign), _ "ProductDesign", _ WellKnownObjectMode.SingleCall)
RemotingConfiguration. _ RegisterWellKnownServiceType( _ GetType(ProductDesign), _ "ProductDesign", _ WellKnownObjectMode.Singleton)
RemotingConfiguration. _ RegisterActivatedServiceType( _ GetType(ProductDesign), _ "ProductDesign")
RemotingConfiguration. _ RegisterWellKnownClientType( _ GetType(ProductDesign), _ "ProductDesign")
-
-
You have designed a remotable class that allows the user to retrieve the latest weather information for her region. You do not want to write a lot of code to create a custom remoting host, so you decide to host the application using IIS. The name of the remotable class is RemotingWeather.WeatherInfo, and it is stored in an assembly named WeatherInfo.dll. You want the users to access this remotable class using the URL http://RemoteWeather.com/users/WeatherInfo.rem. Which of the following remoting configurations would you place in the web.config file so that client applications can correctly retrieve weather information?
<system.runtime.remoting> <application> <service> <activated type= "RemotingWeather.WeatherInfo, WeatherInfo" /> </service> <channels> <channel ref="http" port="80" /> </channels> </application> </system.runtime.remoting>
-
<system.runtime.remoting> <application> <service> <wellknown mode="Singleton" type= "RemotingWeather.WeatherInfo, WeatherInfo" objectUri="WeatherInfo.rem" /> </service> </application> </system.runtime.remoting>
-
<system.runtime.remoting> <application> <service> <activated type= "RemotingWeather.WeatherInfo, WeatherInfo" /> </service> <channels> <channel ref="http server" port="80" /> </channels> </application> </system.runtime.remoting>
-
<system.runtime.remoting> <application> <client> <wellknown mode="Singleton" type= "RemotingWeather.WeatherInfo, WeatherInfo" objectUri="WeatherInfo.rem" /> </client> </application> </system.runtime.remoting>
-
You are a software developer for LubriSol Inc., which manufactures chemicals for automobile industries. Your company does major business with ReverseGear Inc., which is the largest manufacturer of heavy vehicles in the country. ReverseGear, Inc. uses a .NET remoting application that allows its suppliers to check the daily parts requirements. Your objective is to create a client application to the ReverseGear, Inc.'s application that retrieves the information for parts produced by your company. All you know about the server application is its URL, which is http://ReverseGearInc.com/Suppliers/Req.rem. You want the quickest solution. What should you do in order to successfully write a client application?
Contact ReverseGear, Inc. to ask for the interface and include references to the interface in the client project.
Open the URL in the Web browser and select View, Source to find out how the remote class is structured.
Use the Visual Studio .NET Add Web Reference feature to add a reference to the remote class in the client project.
Use the soapsuds tool to automatically generate the metadata and include the reference to this metadata in the client project.
You want to host a remotable class via the .Net remoting framework so that remote clients can instantiate the class and invoke methods on it. The remotable class does not have any user interface, but it must use Integrated Windows authentication to authenticate the users. Which of the following techniques should you use to host the remotable class? You want a solution that requires you to write minimum code.
Use a console application as a remoting host.
Create a Windows service and use that to host the remotable class.
Use a Windows forms application to host the remotable class.
Use Internet Information Services (IIS) as a remoting host.
You are developing a remoting client to access a server-activated remotable object hosted at the URL tcp://finance:1234/Budget. You have obtained an interface assembly of this remote object. This assembly contains an interface named IBudget that is implemented by the remote class. You want to instantiate the remote object to invoke a method named GetDepartmentBudget() that accepts a string value and returns a double value containing the department budget. Given the following code, what should you write in line 08 in order to successfully invoke the GetDepartmentBudget() method? Line numbers are for reference only.
01: ' Register a TCP client channel 02: Dim channel As TcpClientChannel = _ 03: New TcpClientChannel() 04: ChannelServices. _ 05: RegisterChannel(channel) 06: Dim budget As IBudget 07: ' Instantiate the remote class 08: 09: ' Invoke the remote method 10: Dim budgetValue As Double = _ 11: budget.GetDepartmentBudget("HR")
-
budget = CType( _ Activator.GetObject(GetType(IBudget), _ "tcp://finance:1234/Budget"), IBudget)
-
budget = CType( _ Activator.CreateInstance( _ GetType (IBudget), _ "tcp://finance:1234/Budget"), IBudget)
-
budget = New IBudget()
-
RemotingConfiguration. _ RegisterWellKnownClientType( _ GetType (IBudget), _ "tcp://finance:1234/Budget") Budget = new IBudget()
-
You are developing an application that enables client programs to instantiate a class named Inventory. You want the remote object to be created on the server so that it can access the inventory database. However, you want client programs to have control of the creation and the lifetime of the remote objects. Which of the following methods of the RemotingConfiguration class would you choose to register the remotable class with the remoting system on the server?
RegisterWellKnownServiceType()
RegisterWellKnownClientType()
RegisterActivatedServiceType()
RegisterActivatedClientType()
You work for a large chemical manufacturing company that has four production units across the country. Your team has the responsibility of designing a distributed application that allows different production units to share and update material safety information for various products. One of your co-workers is creating a remoting host to host a server-activated object using the following code, but she is getting an error. What should she do to resolve this error?
01: Imports System.Runtime.Remoting 02: Imports System.Runtime. _ 03: Remoting.Channels 04: Imports System.Runtime.Remoting. _ 05: Channels.Tcp 06: Imports System.Runtime.Remoting. _ 07: Channels.Http 08: 09: Sub Main() 10: ' Create and Register channels 11: Dim tcpChannel _ 12: As TcpServerChannel = _ 13: New TcpServerChannel(7777) 14: Dim httpChannel As _ 15: HttpServerChannel = _ 16: New HttpServerChannel(8888) 17: RemotingConfiguration. _ 18: RegisterWellKnownServiceType _ 19: (GetType(MsdsInfo), _ 20: "MsdsInfo", _ 21: WellKnownObjectMode.Singleton) 22: End Sub
Remove the statement in lines 14 through 16.
Add the following statements just before line 17:
ChannelServices.RegisterChannel(tcpChannel) ChannelServices.RegisterChannel( _ httpChannel)
In the statement in lines 11 through 13, replace TcpServerChannel with TcpChannel and similarly in the statement in lines 14 through 16, replace HttpServerChannel with HttpChannel.
Use same port numbers in the statements in line 13 and line 16.
One of your co-workers has written the following code as part of a client application that activates a remote object. She is complaining that her program is not compiling. What should she modify in the program to remove this error? (Select all that apply.)
01: Function CreateObject() As DbConnect 02: ' Create channel 03: Dim channel As TcpClientChannel = _ 04: new TcpClientChannel(1234) 05: ChannelServices.RegisterChannel( _ 06: channel) 07: RemotingConfiguration. _ 08: RegisterWellKnownClientType( _ 09: GetType(DbConnect), _ 10: "tcp://localhost/DbConnect") 11: 12: dbc = new DbConnect() 13: return dbc 14: End Function
Change line 8 to use the RegisterWellKnownServiceType() method instead of the RegisterWellKnownClientType() method.
Change the URL in line 10 to "tcp://localhost:1234/DbConnect".
Remove the port number from the constructor of TcpClientChannel() in line 4.
Change the code in line 10 to objectUri="DbConnect".
The soapsuds tool (soapsuds.exe) can be used to automatically generate the interface assembly for the remotable object. Which of the following statements related to the soapsuds tool are FALSE? (Select two options.)
The soapsuds tool can be used to generate metadata for server-activated objects.
The soapsuds tool can be used to generate metadata for client-activated objects.
The soapsuds tool can be used to generate metadata for remotable objects registered through the HTTP channel.
The soapsuds tool can be used to generate metadata for remotable objects registered through the TCP channel.
You have designed a Windows application that is used by the shipping department of a large distribution house. The Windows application instantiates a remotable class hosted on Internet Information Services (IIS). The remotable class provides various services to the Windows application such as address validation and calculation of shipping rates. When you deploy the application, users complain that when they click the button named Validate Address, the windows application freezes and they can't take further actions until the address has been verified. What should you do to improve the responsiveness of the application?
Use the binary formatter instead of the SOAP formatter.
Use the TCP channel to communicate instead of the HTTP channel.
Modify the remotable class to support asynchronous method calls.
Modify the Windows application to call the methods asynchronously on the remote object.
When you derive a class from MarshalByRefObject to make the class remotable, which of the following members of the class are not remoted? (Select all that apply.)
Non-static public methods
Static methods
Non-static private methods
Non-static public properties
Answers to Review Questions
-
The application domain, or AppDomain, is the basic unit of isolation for running applications in the CLR. The CLR allows several application domains to run within a single Windows process. The CLR ensures that code running in one application domain cannot affect other application domains. The CLR can terminate an application domain without stopping the entire process.
-
MBR objects are remotable objects that derive from the System.MarshalByRefObject class. MBR objects always reside on the server. The client application domain only holds a reference to MBR objects and uses a proxy object to interact with MBR objects. They are best suited when the remotable objects are large or when the functionality of the remotable objects is only available in the server environment on which it is created. However, they increase the number of network roundtrips between the server application domain and the client application domain.
-
A channel is an object that transports messages across remoting boundaries such as application domains, processes, and computers. The .NET Framework provides implementations for HTTP and TCP channels.
-
The Binary formatter represents messages in a compact and efficient way, whereas the SOAP formatter is very verbose. The SOAP formatter can be used to communicate in heterogenous environments, whereas the binary formatter can be understood only by the .NET applications.
-
The two modes to create SAO are SingleCall and Singleton. SingleCall activation mode creates a remote object for each client request. The object is discarded as soon as the request completes. Singleton activation mode creates a remote object only once, and all the clients share the same copy. Hence, SingleCall SAOs are stateless, and Singleton SAOs maintain state global to all clients.
-
CAO are created for each client whenever the client requests. Hence, CAOs are best suited when clients want to maintain private session with remote objects, when the clients want to control the lifetime of the objects, or when they want to create a customized remote object with non-default properties.
-
The main benefit of using declarative configuration over programmatic configuration is that you need not recompile the application after changing the remoting settings in the configuration file. The changes are picked up automatically.
-
The GetObject() (for server-activated objects) and CreateInstance() (for client-activated objects) methods are the two methods of Activator class that allow you to create instances of the remote objects.
-
Using IIS as an activation agent offers the following advantages:
-
You need not write a separate server program to register the remotable classes.
-
You need not worry about finding an available port for your server application. You can just host the remotable object and IIS automatically using the port 80.
-
IIS can provide other functionalities such as authentication and secure socket layers (SSL).
-
-
A remotable object is capable of being called asynchronously by default; therefore, no extra efforts are required in order to create remote objects that can be called asynchronously.
Answers to Exam Questions
A and B. Your objective is to provide access to only authorized clients. Authorization is a function of the remoting host. IIS is the only available remoting host that provides you with this capability. IIS only supports HTTP communication. Therefore, you can use either the HttpChannel or HttpServerChannel channel because both allow you to listen to incoming messages from clients. IIS does not support TcpChannel and TcpServerChannel; therefore, if you use these channels, you'll have to write additional code to implement security, and this is not desired in the given scenario.
C. Firewalls generally allow HTTP messages to pass through, and the binary formatter provides a size-optimized format of encoding data. Using TCP might require administrators to open additional ports in the firewall, whereas the SOAP format is verbose when compared to TCP and would take bandwidth, which is not a desirable solution for clients using slow connections.
A. Only server-activated objects in SingleCall activation mode support load-balancing because they do not maintain state across the method calls.
B. You should store the remoting configuration in a web.config file. This file is an XML-based configuration file that is easy to modify and does not require a separate compilation step. Storing a configuration setting in gwpoinfo.dll or global.asax requires the additional step of compilation before the settings come into effect. The machine.config file is not suggested because any changes done to it will affect all the applications running on the server.
B. When you want to create just one instance of a remote object irrespective of the number of clients, you must create a server-activated (WellKnown) object in the Singleton activation mode.
B. IIS only supports WellKnown or server-activated objects. Therefore, you must use the <WellKnown> element instead of the <activated> element. Also, you are specifying the configuration for the server; therefore, you must use the <server> element instead of the <client> element inside the <application> element to configure the WellKnown object.
D. Because you know that the server's .NET remoting application is using HTTP protocol, you can use the Soapsuds tool to automatically generate the metadata for the server.
D. You should use IIS as the remoting host because IIS has built-in support for Integrated Windows authentication. You'll have to write additional code to achieve this with the other techniques.
A. In a case in which you just have an interface to a class and not the original class, you cannot use the New operator to instantiate the remote object. You should instead use the static methods of the Activator class. The Activator.GetObject() method is used to instantiate a server-activated object, whereas Activator.CreateInstance() method is used to instantiate a client-activated object.
C. Your requirement is to register a client-activated remote object; therefore, you'll use the RegisterActivatedServiceType() method. The RegisterActivatedClientType() method is used to register the CAO with the remoting system in the client's application domain. The other two options are for creating the server-activated objects.
B. In the preceding program, although you have created an instance of TcpServerChannel and HttpServerChannel objects, you haven't yet registered them with the remoting framework. You'll register the channels using the RegisterChannel() method of the ChannelServices class.
B and C. When creating a client channel, you should not specify a port number with the channel constructor. Instead, the port number should be used with the URL of the remote object.
B and D. The soapsuds tool is capable of generating metadata for server-activated objects on the HTTP channel.
D. The issue in the question is not of speed but of responsiveness. This behavior is because the Windows application is calling the methods on the remote object synchronously. You can make the user interface more responsive by simply calling the remote method asynchronously. No modifications are needed on the remotable object to achieve this behavior.
B and C. Only non-static public methods, properties, and fields participate in remoting.
Suggested Readings and Resources
-
Visual Studio .NET Combined Help Collection
-
.NET Remoting Overview
-
Remoting Examples
-
-
Ingo Rammer. Advanced .NET Remoting. Apress, 2002.
-
http://www.iana.org/assignments/port-numbersList of assigned port numbers.