Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Writing Advanced .NET Remoting Clients : Page 2

.NET Remoting provides a powerful way to use remote objects as if they existed locally, using interfaces and the factory pattern.


advertisement
An interface in C# is a pattern for a class with methods defined but left empty. Basically an interface defines the methods, parameters, and return values implementations of your interface must have.

In a Remoting context, think of the interface as being an agreement reached between the client and the server; interfaces provide the glue that allows lets the client and server play together nicely. You can imagine the client as thinking, "If I give you an integer for the WhatIsTwoPlusTwo() method, I want a string back." Meanwhile, the server is thinking, "If you give me an integer for the WhatIsTwoPlusTwo method, I will perform my logic on that integer and give you a string back."

The interface becomes a kind of symbolic version of the object that actually resides on the server. Your client side remoting code uses only the interfaces and not the actual objects. When your application runs it uses the object instantiated on the remote server transparently, even though your client side code has knowledge only of the interface.

In this article, you'll see an example implementation designed to evaluate whether a test taker would make a good corporate accountant for a large energy company.

The interface for the sample code is simple, and contains only two methods. The method WhatIsTwoPlusTwo()must accept an integer for the answer argument, and returns a string. The method SetName() which accepts a string and returns nothing. The SetName() method should probably set a variable containing the name of the person taking the test, but remember that the methods in this interface are not implemented yet. You'll write the implementation in the next section.

public interface IAccountantTest { string WhatIsTwoPlusTwo(int answer); void SetName(string name); }

Put all your interfaces in a separate DLL project. Both the client and the server will need their own interface copies. Listing 1 contains a complete listing of the interface code.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap