|
using System;
using System.Threading;
using System.Diagnostics;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using MyRemoteObject;
namespace ConsoleClient
{
class Client
{
static void Main(string[] args)
{
int ii = 0;
try
{
RemotingConfiguration.Configure(@"..\..\ConsoleClient.exe.config");
// activate a remote object
Type objectType = typeof(MyRemoteObject.RemoteObject);
//string objectUrl = @"ws://localhost/WebServiceListener/Listener.asmx; tcp://localhost:8090/endpoint";
string objectUrl = @"ws://localhost/WebServiceListener/Listener.asmx; msmq://./reqchannel/endpoint";
RemoteObject ro = (RemoteObject)Activator.GetObject(objectType, objectUrl);
Console.Write("Type your name: ");
string name = Console.ReadLine();
string[] firstlastName = name.Split(new char[]{' '});
// Call Context
User user = new User();
user.firstname = firstlastName.Length > 0 ? firstlastName[0] : "";
user.lastname = firstlastName.Length == 2 ? firstlastName[1] : "";
CallContext.SetData("User", user);
while(true)
{
Console.Write("Hit any key to make a test.");
string reqmsg = Console.ReadLine();
Console.WriteLine(string.Format("State: Id={0}; Name={1}\n", ro.Id, ro.Name));
string respond = null;
object str = null;
object retval = ro.SayHello(reqmsg, out respond, ii++, out str);
Console.WriteLine(string.Format("\nReturned Values: {0} {1}", respond, str));
Console.WriteLine(retval);
User u = (User)CallContext.GetData("User");
Console.WriteLine("CallContext: {0}, {1}, {2}", u.GetType(), u.firstname, u.lastname);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
System.Console.ReadLine();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.