.NET Remoting basics

November 26, 2009

Remoting has been a topic of my interest right from early days of .NET. Here is just an beginner’s tutorial.

1. Whats Remoting?

A: In one line – Interprocess communication in distributed computing.

2. How far distributed?

A: Across the world over internet.

3. Unterstanding remoting from a simple use case?

A: There are 3 parts to the simple use case for remoting:

          a. Remotable object. (Data which travels on the channel)
          b. Host application domain to listen for requests for that object. (Server)
          c. Client application domain that makes requests for that object. (Client)

Lets start with a simple application in Visual Studio…the project will demonstrate a Patient service and remotable Patient objects.

There will be 4 projects

1. Remoting.ClientAccess (Just the interface which the client needs to access the objects on the server)
2. Remoting.ServerObject (Implementation of the interfaces from point 1)
3. RemotingServer (The console application running as server to listen to requests)
4. RemotingTest (The client console application which will make RPCs using the interfaces in point 1)

Project 1 //Remoting.ClientAccess //build it into a library

namespace Remoting.ClientAccess
{
    public interface IPatient
    {
        int PatientCode { get; set; }
        string FirstName { get; set; }
        string LastName { get; set; }
        int HospitalCode { get; set; }       
    }
}

namespace Remoting.ClientAccess
{
    public interface IPatientService
    {
        void SavePatient(IPatient patient);
    }
}

Project 2 //Remoting.ServerObject // build as a library //reference to project 1

namespace Remoting.ServerObjects
{
    [Serializable]
    public class Patient : System.MarshalByRefObject ,IPatient
    {
        private int ptCode;
        private string fName;
        private string lName;
        private int hospCode;
        #region IPatient Members

        public int PatientCode
        {
            get
            {
                return ptCode;
            }
            set
            {
                ptCode = value;
            }
        }

        public string FirstName
        {
            get
            {
                return fName;
            }
            set
            {
                fName = value;
            }
        }

        public string LastName
        {
            get
            {
                return lName;
            }
            set
            {
                lName = value;
            }
        }

        public int HospitalCode
        {
            get
            {
                return hospCode;
            }
            set
            {
                hospCode = value;
            }
        }
       
        #endregion
    }

}

[Serializable]
    public class PatientService : System.MarshalByRefObject, IPatientService
    {

        #region IPatientService Members

        public void SavePatient(IPatient patient)
        {
            Console.WriteLine(“First name : ” + patient.FirstName);
            Console.WriteLine(“Last name : ” + patient.LastName);
            Console.WriteLine(“Code : ” + patient.PatientCode);
            Console.WriteLine(“Hosp code : ” + patient.HospitalCode);
        }      

        #endregion
    }

Project 3 //RemotingServer // build as a console application //reference to project 1,2

namespace RemotingServer
{
    class Program
    {       
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure(“RemotingServer.exe.config”);
          
            Console.WriteLine(“Press return to exit”);
            Console.ReadLine();
        }
    }
}

Here is the config file which is used in above code:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
  <system.runtime.remoting>
    <application>
      <service>
        <wellknown mode=”Singleton” type=”Remoting.ServerObjects.Patient, Remoting.ServerObjects” objectUri=”Patient.rem” />
        <wellknown mode=”Singleton” type=”Remoting.ServerObjects.PatientService, Remoting.ServerObjects” objectUri=”PatientService.rem” />
      </service>
      <channels>
        <channel ref=”tcp” port=”8000″>
          <serverProviders>
            <!–provider ref=”wsdl” / –>
            <!–formatter ref=”soap” typeFilterLevel=”Full” /–>
            <formatter ref=”binary” typeFilterLevel=”Full” />
          </serverProviders>
          <!–clientProviders>
            <formatter ref=”binary” />
          </clientProviders–>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>

Project 4 //RemotingTest // build as a console application //reference to project 1

namespace RemotingTest
{
    class Program
    {
        static void Main(string[] args)
        {
           
            IPatientService ptSvc = (IPatientService)Activator.GetObject(typeof(IPatientService), “tcp://172.16.11.22:8000/PatientService.rem”);
            IPatient pt = (IPatient)Activator.GetObject(typeof(IPatient), “tcp://172.16.11.22:8000/Patient.rem”);
            pt.FirstName = “Vaibhav”;
            pt.LastName = “Gaikwad”;
            pt.PatientCode = 23423 ;
            pt.HospitalCode = 234 ;
            ptSvc.SavePatient(pt);
        }
    }
}

Execute the server application and then execute the client application

MAHADA lottery 2009

May 20, 2009

For those who are looking the net for direct link to the results:

http://mhada.maharashtra.gov.in/?q=lottery3863

The above link will display a table which all the schemes and categories, which can lead you to the respective PDF files which contains the results. So how to directly access the results, here is how it goes…

General link discovery:

http://www.graphitech.in/mhada/win/207SCWIN.pdf means scheme=207, category=SC, WIN stands for winner and is common for all the links.

So if you want to see results for scheme 227 with category SG then try access file 227SGWIN.pdf on the same base url, this is true for all the schemes and categories.

Categories:

SC
ST
NT
DT
JR
FF
PH
DF
EX
MLA 
ME
SG
CG
AR
GP

For scheme code check you application forms :)

Best of luck ;)

Ever thought of getting dynamic web reference from a WSDL? Then making dynamic proxies, and invoking the methods dynamically.

I had some requirement which includes all of the above topics. So after completing my test code I thought of publishing it here for educational purposes.

check it out if you need to do something similar or if you are stuck with some intermediate part:

http://vaibhavgaikwad.wordpress.com/web-services-with-reflection-in-net/

-Bugs!

Here is how you can do that:

http://vaibhavgaikwad.wordpress.com/reflection-with-interfaces-with-c/

-Bugs!

Recently when I was trying to install some new packages on my laptop, I got the below stated error:

vaibhav@vaibhav-laptop:~/web_dev/asp.net$ sudo apt-get install subversion
Password:
Reading package lists… Error!
E: Dynamic MMap ran out of room
E: Error occurred while processing trn4 (NewVersion1)
E: Problem with MergeList /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_dapper_multiverse_binary-i386_Packages
E: The package lists or status file could not be parsed or opened.
vaibhav@vaibhav-laptop:

Did some internet search on it but was helpless. Then finally one article stated that it might be a cache size issue for apt-get, and the resolution was to add the below line in /etc/apt/apt.conf, but that file was missing.

“APT::Cache-Limit “8388608″;

So here is how you can resolve the issue without the apt.conf file.

sudo apt-get update -o APT::Cache-Limit=8388608

-Bugs! 

HL7 v3.0 message handling.

February 12, 2008

Health Level 7 (www.hl7.org) has released version 3.0 for quite a while back, and I have to work on its message handling and integration with health care applications. The new version completely focuses on XML based messages. The Normative Edition comes with a good load of xsds (XML Schema Definition); one for each message type and believe me there are tons of xsds. The message structure has got very much readable and easy to parse using any language which has good xml parser as compared to version 2.x.
The best approach which I can think of for now, is using the xsds do generate classes. I tried to use XSD.exe from the Visual Studio 2005 Tools, but I was unable to fix the reference types. The xsd.exe tool does not take into account the referenced schema definitions, and so I was not able to auto-generate class from those xsd, but when I get that done then I have no big headache. Once the classes are generated, we can just use XmlSerializer class to DeSerialize the xml-message directly to the class and then access the respective properties. Looks simple?

I tried the same trick within a test application which has “shiporder.xml” and “shiporder.xsd”, these files were taken from w3c :)
http://www.w3schools.com/schema/schema_example.asp

I created the class using xsd.exe from VS.NET tools, which created “shiporder.cs” for me:
cmd>> xsd shiporder.xsd /c

Then I build a simple and sweet standalone application to test it.
//code c#
using System.IO;
using System.Xml.Serialization;
namespace XSDTest
{
class Program
{
static void Main(string[] args)
{

// shiporder.cs
XmlSerializer serial = new XmlSerializer(typeof(shiporder));
TextReader reader = new StreamReader(“shiporder.xml”);

// this is how you directly get the data back.
shiporder so = (shiporder) serial.Deserialize(reader);

}
}
}
//end code
 

I hope I will be able to resolve the reference schemas in the HL7 xsds, and then build the classes out of it in near future, till then try out other possible methods :) -Bugs

Great news!

November 30, 2007

Currently, I was doing some development work on Ubuntu’s v7.04 (Fiesty Fawn), just for a note “it’s a great OS”. I had also ordered the CDs for the latest version 7.10 (Gusty Gibbon), which I received today. I am not very much excited to play with this new version. Just later, I was surfing the net to find some cool appz for Gusty and found out that there was a another version planned to be released on April 2008, this will be 8.04 (Hardy Heron). I just can’t wait to put my hands on Hardy :)

-Bugs!

Follow

Get every new post delivered to your Inbox.