Apply Your Knowledge
Exercises
3.1 - Using HTTP Channels with Binary Formatters
As I discussed in the chapter, the default formatter for the HTTP channel is SOAP, and for the 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 320C03Exercises. 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).
-
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:
<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>
IIS is now hosting the StepByStep3_10.DbConnect remotable class as a server-activated object by using the Singleton activation mode.
-
Add a new Visual C# .NET Windows application named Exercise3_1_Client to the solution.
-
Add references 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 tool bar. Move the Exercise3_1_Client.exe.config file from the project folder to the bin\Debug folder under the project, where the Exercise3_1_Client.exe file will be created when the project is compiled.
-
In the Solution Explorer, rename the default Form1.cs to DbConnectClient.cs. Open the form in code view and change all occurrences of Form1 to refer to DbConnectClient instead.
-
Place two GroupBox controls (grpQuery and grpResults), a TextBox control (txtQuery, with its MultiLine property set to true), a Button control (btnExecute), and a DataGrid control (dgResults) on the form. Refer to Figure 3.5 for the design of this form.
-
Add the following using directives:
-
Add the following code in the class definition:
-
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 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. The code binds the results from the remote method to the DataGrid control.
<configuration> <system.runtime.remoting> <application> <channels> <channel ref="http"> <serverProviders> <formatter ref = "binary" /> </serverProviders> </channel> </channels> </application> </system.runtime.remoting> </configuration>
using System.Runtime.Remoting; using StepByStep3_9;
// Declare a Remote object IDbConnect dbc;
private void DbConnectClient_Load( object sender, System.EventArgs e) { // Load remoting configuration RemotingConfiguration.Configure ("Exercise3_1_Client.exe.config"); // Instantiate the remote class dbc = (IDbConnect) Activator.GetObject(typeof(IDbConnect), @"http://localhost/Exercise3_1_Server/DbConnect.rem"); }
private void btnExecute_Click( object sender, System.EventArgs e) { try { // Invoke a method on // the remote object this.dgResults.DataSource = dbc.ExecuteQuery( this.txtQuery.Text); dgResults.DataMember = "Results"; } catch(Exception ex) { MessageBox.Show(ex.Message, "Query Execution Error"); } }
Note that you can specify the desired formatter for the client and need not specify the 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 Well-Known Object
Well-known objects cannot be invoked from a client with a non-default constructor. However, you can create an object using any constructor you wish, initialize it any way you wish, and then make it available to clients.
You should use the RemotingServices.Marshal() method to publish an existing object instance.
Estimated Time: 30 minutes.
-
Add a new Visual C# console application named Exercise3_2_Server to the solution.
-
Add references to the .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 Class1.cs to DbConnectServer.cs. Open the file and change the name of the class to DbConnectServer in the class declaration.
-
Add the following using directives:
-
Add the following code in the Main() method:
-
Build the project. This step creates a remoting server that creates the remotable object StepByStep3_1.DbConnect and is capable of marshaling the remote object across application boundaries.
-
Add a new Visual C# .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, rename the default Form1.cs to DbConnectClient.cs. Open the form in code view and change all occurrences of Form1 to refer to DbConnectClient instead.
-
Add the following using 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 database names in the editor:
-
Click OK to add the databases to the Items collection of the cboDatabases control.
-
Add the following code in the class definition:
-
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 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 activation mode. You should also see messages that the remote object is already created.
-
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.
-
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.
using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using StepByStep3_10;
[STAThread] static void Main(string[] args) { // Create and register a TCP server // channel that listens on port 1234 TcpServerChannel channel = 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 DbConnect dbcPubs = new DbConnect("Pubs"); RemotingServices.Marshal( dbcPubs, "Pubs.uri"); DbConnect dbcNorthwind = 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(); }
using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using StepByStep3_9;
Northwind Pubs
// Declare a remote object IDbConnect dbc;
private void DbConnectClient_Load( object sender, System.EventArgs e) { // Register a TCP client channel TcpClientChannel channel = new TcpClientChannel(); ChannelServices.RegisterChannel( channel); cboDatabases.SelectedIndex = 0; }
private void cboDatabases_SelectedIndexChanged( object sender, System.EventArgs e) { switch ( cboDatabases.SelectedItem.ToString()) { case "Pubs": { // Instantiate the remote class dbc = (IDbConnect) Activator.GetObject( typeof(IDbConnect), @"tcp://localhost:1234/Pubs.uri"); break; } case "Northwind": { // Instantiate the remote class dbc = (IDbConnect) Activator.GetObject( typeof(IDbConnect), @"tcp://localhost:1234/Northwind.uri"); break; } } }
private void btnExecute_Click (object sender, System.EventArgs e) { try { // Invoke a method on // the remote object this.dgResults.DataSource = dbc.ExecuteQuery( this.txtQuery.Text); dgResults.DataMember = "Results"; } catch(Exception ex) { MessageBox.Show(ex.Message, "Query Execution Error"); } }
Review Questions
What is an application domain? How does the CLR manage an application domain?
What are MBR objects? What are their advantages and disadvantages?
What do you mean by a channel? What are the different types of channels the .NET Framework provides?
What are the advantages and disadvantanges of the binary and SOAP formatters?
What are the two modes for creating 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 enable you to create instances of remote objects?
What are the advantages of using an 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 applications to activate the remote object. You want to write the application with the minimum amount of code. Which of the following channels enables you to achieve this objective? (Select two.)
-
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, Washington, 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 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 combinations of channel and formatter 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 enables their suppliers to access the purchase order information in real time. You create the required classes that the suppliers can activate remotely and package them into a file named gwpoinfo.dll. You plan to use IIS as the remoting host for this file. After the application has been deployed, minimal steps should be involved in changing the remoting configuration for this application. Any config-uration 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 client programs should be able to remotely instantiate objects of this class and invoke methods on it. You want to have only one instance of this class on the server, no matter how many clients connect to it. Which of the following code segments fulfills your requirement?
-
-
RemotingConfiguration. RegisterWellKnownServiceType( typeof(ProductDesign), "ProductDesign", WellKnownObjectMode.SingleCall );
-
RemotingConfiguration. RegisterWellKnownServiceType( typeof(ProductDesign), "ProductDesign", WellKnownObjectMode.Singleton );
-
RemotingConfiguration. RegisterActivatedServiceType( typeof(ProductDesign), "ProductDesign" );
-
RemotingConfiguration. RegisterWellKnownClientType( typeof(ProductDesign), "ProductDesign" );
-
- You have designed a remotable class that allows the user to retrieve the
latest weather information for their region. You do not want to write a lot
of code to create a custom remoting host, so you decide to use IIS to host
the application. 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 by 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 a lot of 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 its daily parts requirements. Your objective is to create a client application to the ReverseGear'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 to write a client application successfully?
-
Contact ReverseGear, Inc., to ask for the interface and include reference to the interface in the client project.
-
Open the URL in the Web browser and select View, Source to find 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 you should use to host the remotable class? You want a solution that requires you to write minimal 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 name GetDepartmentBudget(), which accepts a string value and returns a double value containing the department budget. Given the following code, what should you write in line 06 to successfully invoke the GetDepartmentBudget() method?
01: // Register a TCP client channel 02: TcpClientChannel channel = new TcpClientChannel(); 03: ChannelServices.RegisterChannel( channel); 04: IBudget budget; 05: // Instantiate the remote class 06: 07: // Invoke the remote method 08: double budgetValue = budget.GetDepartmentBudget("HR");
-
budget = (IBudget) Activator.GetObject(typeof(IBudget), @"tcp://finance:1234/Budget");
-
budget = (IBudget) Activator.CreateInstance( typeof(IBudget), @"tcp://finance:1234/Budget");
-
budget = new IBudget();
-
RemotingConfiguration. RegisterWellKnownClientType( typeof(IBudget), @"tcp://finance:1234/Budget"); Budget = new IBudget();
-
-
You are developing an application that allows the 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 control 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 using the following code to create a remoting host to host a server-activated object. She is getting an error. What should she do to resolve this error?
01: using System.Runtime.Remoting; 02: using System.Runtime.Remoting.Channels; 03: using System.Runtime.Remoting.Channels.Tcp; 04: using System.Runtime.Remoting.Channels.Http; 05: [STAThread] 06: static void Main(string[] args) 07: { 08: TcpServerChannel tcpChannel = new TcpServerChannel(7777); 09: HttpServerChannel httpChannel = new HttpServerChannel(8888); 10: RemotingConfiguration. RegisterWellKnownServiceType (typeof(MsdsInfo), "MsdsInfo", WellKnownObjectMode.Singleton); 11: }
-
Remove the statement at line 09.
-
Add the following statements just before line 10:
ChannelServices.RegisterChannel(tcpChannel);
ChannelServices.RegisterChannel(httpChannel); -
In the statement at line 08, replace TcpServerChannel with TcpChannel, and similarly in the statement in line 09, replace HttpServerChannel with HttpChannel.
-
Use the same port numbers in the statements in line 08 and line 09.
-
-
One of your coworkers 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: DbConnect CreateObject() 02: { 03: TcpClientChannel channel = new TcpClientChannel(1234); 04: ChannelServices.RegisterChannel( channel); 05: RemotingConfiguration. RegisterWellKnownClientType( 06: typeof(DbConnect), 07: "tcp://localhost/DbConnect" 08: ); 09: dbc = new DbConnect(); 10: return dbc; 11: }
-
Change line 05 to use the RegisterWellKnownServiceType() method instead of the RegisterWellKnownClientType() method.
-
Change the URL in line 07 to "tcp:// localhost:1234/DbConnect"
-
Remove the port number from the constructor of TcpClientChannel() in line 03
-
Change the code in line 07 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 are FALSE related to the Soapsuds tool? (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 Validate Address button, the Windows application freezes and they can't take further action till the address has been verified. What should you do to improve the application's responsiveness?
-
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 the 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, represented by the AppDomain class, 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. The MBR objects always reside on the server; the client application domain holds only a reference to the MBR objects and uses a proxy object to interact with the MBR objects. They are best suited when the remotable objects are large or when the functionality of the remotable objects is available only 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 formatters are very verbose. The SOAP formatters can be used to communicate in heterogeneous environments, whereas the binary formatters can be understood only by .NET applications.
-
The two modes for creating SAOs 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.
-
CAOs are created for each client whenever the client requests. Hence CAOs are best suited when clients want to maintain private sessions with remote objects, when the clients want to control the lifetimes of the objects, or when they want to create customized remote objects 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() method (for server-activated objects) and CreateInstance() method (for client-activated objects) are the two methods of the Activator class that enable you to create instances of 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 uses port 80.
-
IIS can provide other functionality, such as authentication and Secure Sockets Layer (SSL).
-
-
A remotable object by default is capable of being called asynchronously; therefore no extra efforts are required to create remote objects that can be called asynchronously.
Answers to Exam Questions
A, 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 supports only 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, so if you use these channels you have to write additional code to implement security and this is not desired in the given scenario. For more information, see the section "Choosing Between the HTTP and the TCP Channels" in this chapter.
C. Firewalls generally allow HTTP messages to pass through, and the binary formatter provides a size-optimized format for encoding data. Using TCP may require administrators to open additional ports in the firewall, and the SOAP format is verbose when compared to binary and would take additional bandwidth, which is not a desirable solution for clients using slow connections. For more information, see the section "Choosing Between the HTTP and the TCP Channels" and "Channels and Formatters" in this chapter.
A. Only server-activated objects in SingleCall activation mode support load-balancing because they do not maintain state across the method calls. For more information, see the section "Server-Activated Objects" in this chapter.
B. You should store the remoting configuration in the 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 configuration settings 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 made to it affect all the applications running on the server. For more information, see the section "Using Configuration Files to Configure the Remoting Framework" in this chapter.
B. When you want to create just one instance of a remote object, without regard to the number of clients, you must create a server-activated object in the Singleton activation mode. For more information, see the section "Server-Activated Objects" in this chapter.
B. IIS supports only well-known or server- activated objects. Therefore, you must use the <wellknown> element rather than the <activated> element. Also, you are specifying the configuration for the server, so you must use the <server> element rather than the <client> element inside the <application> element to configure the WellKnown object. For more information, see the section "Using Configuration Files to Configure the Remoting Framework" and "Using IIS As an Activation Agent" in this chapter.
D. Because you know that the server's .NET remoting application is using HTTP, you can use the Soapsuds tool to automatically generate the metadata for the server. For more information, see the section "Using the Soapsuds Tool to Automatically Generate an Interface Assembly" in this chapter.
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 other techniques. For more information, see the section "Using IIS As an Activation Agent" in this chapter.
A. When you 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. For more information, see the section "Using Interface Assemblies to Compile Remoting Clients" in this chapter.
C. Your requirement is to register a client-activated remote object on the server, so 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. For more information, see the section "Creating a Client-Activated Object" in this chapter.
B. In this 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 by using the RegisterChannel() method of the ChannelServices class. For more information, see the sections "Using the SingleCall Activation Mode to Register a Remotable Class As a Server-Activated Object," "Using the Singleton Activation Mode to Register a Remotable Class As a Server-Activated Object," and "Registering a Remotable Class As a Client-Activated Object" in this chapter.
B, C. When creating a client channel you should not specify a port number when calling the channel constructor. Instead, the port number should be used with the URL of the remote object. After the channels are created they should be registered with the remoting system. For more information, see the section "Channels" in this chapter.
B, D. The Soapsuds tool is capable of generating metadata for server-activated objects on the HTTP channel. For more information, see the section "Using the Soapsuds Tool to Automatically Generate an Interface Assembly" in this chapter.
D. The issue in the question is not of speed but of responsiveness. This behavior occurs 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. For more information, see the section "Asynchronous Remoting" in this chapter.
B, C. Only non-static public methods, properties, and fields participate in remoting. For more information, see the section "Remote Object Activation" in this chapter.
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.