Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / November 2005

Tip: Looking for answers? Try searching our database.

Forging responses on intercepted call.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frosty Madness - 31 Oct 2005 11:35 GMT
I've implemented a custom RealProxy for an object I want to test. I'm
using a proxy because I want to log what calls are made to this object.

Using the example in MSDN on RealProxy, I can easily log what is passed
to the objects but here's the sticking point. I don't want to actuall
call the object in question, I'd like to return a 'forged' return
message.

Any suggestion as to how I'd do this?

Cheers,

Jack
Robert Jordan - 31 Oct 2005 13:11 GMT
> I've implemented a custom RealProxy for an object I want to test. I'm
> using a proxy because I want to log what calls are made to this object.
[quoted text clipped - 5 lines]
>
> Any suggestion as to how I'd do this?

Well, you name it: don't call the target object from the Invoke
method of your custom proxy and fake the return message ;-)

public override IMessage Invoke (IMessage myMessage)
{
  ...

  MethodResponse resp = new MethodResponse (
    new Header[] {new Header("__Return", someFakedReturnValue)},
    myMessage);

  return resp;
}

Rob
Frosty Madness - 01 Nov 2005 10:04 GMT
Thanks for that, works great. The MethodResponse class was the hole in
my knowledge. But there's a wrinkle...

In order to send back the out parameters, I need to check which of the
args are out or ref. How do I do that?

Cheers
Robert Jordan - 01 Nov 2005 11:09 GMT
> Thanks for that, works great. The MethodResponse class was the hole in
> my knowledge. But there's a wrinkle...
>
> In order to send back the out parameters, I need to check which of the
> args are out or ref. How do I do that?

public override IMessage Invoke (IMessage myMessage)
{
  ...

  MethodBase mb = RemotingServices.GetMethodBaseFromMethodMessage (
    (IMethodMessage)myMessage);

  ArrayList outParams = new ArrayList ();
  foreach (ParamaterInfo p in mb.GetParameters ())
  {
    if (p.IsOut) outParams.Add(someFakedOutValue);
  }

  Header[] headers;
  if (outParams.Count > 0)
  {
    headers = new Header[2];
    headers[0] = new Header("__Return", someFakedReturnValue)};
    headers[1] = new Header("__OutArgs", outParams.ToArray ());
  }
  else {
    headers = new Header[1];
    headers[0] = new Header("__Return", someFakedReturnValue)};
  }

  MethodResponse resp = new MethodResponse (headers, myMessage);

  return resp;
}

Rob

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.