.NET
  Home arrow .NET arrow Page 6 - Introduction to RPC on Windows: Part I
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Introduction to RPC on Windows: Part I
By: Digvijay Chauhan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 20
    2005-01-10

    Table of Contents:
  • Introduction to RPC on Windows: Part I
  • Meet IDL
  • Doing the RPC stuff
  • Writing Server Side code
  • Writing Client Side Code
  • Points of Interest

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to RPC on Windows: Part I - Points of Interest


    (Page 6 of 6 )

    Here are a few points of interest that you might like to know before developing any other RPC applications.

    Debugging RPC Applications

    If you encounter problems when debugging and you end up finding that the problem is in a MIDL generated file, start over; the real problem is in the client or in the server and not in the MIDL generated code. This article is meant to get you started using RPC, but in a future article I will describe these topics in detail.

    Types of binding handles

    When using RPC, the binding handles can be implicit (implicit_handle) or explicit (explicit_handle). I always use explicit handles since I'm sometimes connected to multiple servers that do not work with the implicit handle. To use explicit handles, you'll have to change the IDL file, the server and the client. The difference will be in the interface member definition. Now each method defined in the interface will have a handle as its first argument.

    // File DoRPCExp.idl
    [
    // A unique identifier that distinguishes this
    // interface from other interfaces.
     // this is version 1.0 of this interface.
    uuid(2BC900B0-9E3F-451c-A134-581B6328E2CA),

    version(1.0),
    // this interface uses explicit binding handle.

    explicit_handle
    ]

    interface DoRPCExplicit // The interface is named DoRPCExplicit
    {
    // A function that takes a binding handle and a char string.
    void Show( [in] handle_t hBinding, [in, string] const char* szMsg);
    }

    There is also a handle type known as  auto_handle, that allows you to connect and invoke RPC functions on the server automatically without maintaining a RPC handle.

    The Application Configuration File (ACF)

    The DoRPC example uses an implicit_handle that is a Microsoft extension. You may use the explicit_handle directly in the IDL file, and in that case you won’t need an ACF file because each interface method will absorb the handle as its first argument (as shown above). You may try that by modifying the code provided with this article just to see it working. In case of implicit handles, one usually needs to use a separate Application Configuration File that contains the handles that you wish to use. We’ll see more on ACF files later.

    Trust MIDL

    One should not modify the MIDL generated files to make them compile; they ought to be correct. Please do check the switches to midl.exe if you feel that they are incorrect and you need some results other than default. Sometimes when compiling MIDL generated source code, you may get a lot of warning messages. You may lower the warning level to two in the C/C++ tab in Project Settings to make them silent.

    Shutting down the server

    The server we just wrote runs indefinitely until it is forced to shut down by closing the console. That truly isn’t the best way of doing it. A better way is to call the RpcMgmtStopServerListening function that makes the server stop listening. You might be thinking: “If I don’t get back from the RpcServerListen function, how am I supposed to call this function?” You could add another function to the interface (StopServer() is a good candidate!!) that will call RpcMgmtStopServerListening or you could create another thread in the server before calling RpcServerListen that will call RpcMgmtStopServerListening after a predefined time interval or on a particular event.

    Summary

    This article introduced you to the world of RPC and using it to develop client/server applications. If you really want to take advantage of this technology, just glance through the examples in the Platform SDK samples. They’re a great place to start. I shall discuss more complex issues in the RPC world in my future articles.

    References

    • MSDN - MIDL and RPC
    • MSDN - Remote Procedure Call

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi,I was able to compile the *.idl file. But I am getting an error while trying to...
       · i successfully compile the code...but when i running server program i got pop up...
       · First of all I would like to thank you for such wonderful articles on smart card and...
       · You may use the Smart Client like approach to execute Smart Card commands via the...
       · Its very kind of you to respond to my query. We were going through a office move and...
       · It's simple,a C# or J# script would do the job ...... only required thing is...
       · Hi DigvijayThanks very much for the response, but I am still struggling how to...
       · Hi,I believe i conveyed something wrong.What i meant was ........ after...
       · I am so sorry, this is my first ever attempt on .net and I am still not quite sure ...
       · First ..... You need not register the script if you have it running on the client...
       · I think I now understand whats happening.This is my latest codeprivate void...
       · Dear Friend,You've done it finally.Just enable Smart Clients on the client...
       · Hithanks for good article.I have some problem with MIDLhow I can get...
     

    .NET ARTICLES

    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway