Print Page | Close Window

Remote Service Method Call

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2402
Printed Date: 30-Aug-2025 at 12:44am


Topic: Remote Service Method Call
Posted By: gregweb
Subject: Remote Service Method Call
Date Posted: 27-Dec-2010 at 5:53am
I am trying to get a RSMC to work as per http://drc.ideablade.com/xwiki/bin/view/Documentation/QueryRSMC - http://drc.ideablade.com/xwiki/bin/view/Documentation/QueryRSMC
 
On the server I have a class called MailService like this:
 
namespace Jet.Services
{
    public static class MailService
    {
        [AllowRpc]
        public static object GetNewMail(IPrincipal pPrincipal, EntityManager pPm, params Object[] pArgs )
        {
            Debug.WriteLine("Getting New Mail");
            return "Got Mail";
        }

    }
}
I link this class in the SL project so I have a reference to it.  I then call it like this on the client:
internal void GetMail()
{
            object[] parms = new object[] { "Test" };
            //string methodName = "GetNewMail";
            ServerMethodDelegate del = Jet.Services.MailService.GetNewMail;
var op  = _mgr.InvokeServerMethodAsync( del, parms);
}
 
This compiles.  But when I run it, I get the following exception:
 
Unable to load type: Jet.Services.MailService, Jet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 
I looked for a sample in DRC_SampleCode, but didn't find one.
 
Greg
 
 
 
 
 
 



Replies:
Posted By: sbelini
Date Posted: 28-Dec-2010 at 4:27pm
Hi Greg,
 
You are getting this error because when you create a delegate in the client, its full type name is
 
Jet.Services.MailService, Jet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 
but in the server, the Assembly name is most likely JetWeb. (I'm guessing the server assembly name is JetWeb based on the assumption that you created your project using the Silverlight template)
 
To get rid of the error, you could:
1) change the Assembly name of the server to match the SL project's. This is possible, but NOT advisable as it could cause other adverse effects.
 
2) use the
  public InvokeServerMethodOperation InvokeServerMethodAsync( 
    string fullTypeName,
    string methodName,
    Action<InvokeServerMethodOperation> userCallback,
    object userState,
    params object[] userArguments
  )
overload.
 
Silvio.


Posted By: gregweb
Date Posted: 29-Dec-2010 at 5:43am

Hi Silvio,

Thanks very much, I am going to try number 2 above.  I found a good sample of this in the AuthenticationManager:
 
// Call a server-side method.  Note type name must be fully-qualifed:  MyNamespace.MyClass, MyAssemblyName
            string typeName = "Jet.RegistrationServices, Jet.Web";
            string methodName = "CreateUser";
            var op1 = Manager.InvokeServerMethodAsync(typeName, methodName, nullnull, user, password);
            yield return op1;
            CreateUserResult result = op1.Result as CreateUserResult;
            if (result.Status != CreateUserStatus.Success)
            {
                // Throw an exception here - the caller can decide what to do.  
                throw new RegistrationException(result);
            }
 
I also tried setting the assembly name in the Project Properties to Jet from Jet.Web, and this also worked! 
 
Greg



Print Page | Close Window