locked
How to call invoke method with parameter object RRS feed

  • Question

  • User296208726 posted

    Hello. I want to pass argument "customerObject" by method "invoke" from .Net client Xamarin Mobile to serverHub.

    My code CustomerHub: 

    public class CustomerHub : Hub{
    
    public void SendMessage(string message, Customer customerObject){
    
    }
    }


    Calling from Xamarin Mobile:

    var hubConnection = new HubConnection(customerUrlHub);
    var hubProxy = hubConnection.CreateHubProxy("CustomerHub");
    hubProxy.Invoke("SendMessage","Hello world", modelCustomerObject); //Passing argument from .Net Xamarin doesn't work

    when I removed argument "cutomerObject, It will be work, but It does not suit me, How to call invoke method from .net Xamarin with object?

    Also I tried to convert modelCustomerObject to Json:

    string jsonObject = JsonConvert.SerializeObject(modelCustomerObject);// serialization modelCustomerObject
    var
    hubConnection = new HubConnection(customerUrlHub); var hubProxy = hubConnection.CreateHubProxy("CustomerHub"); hubProxy.Invoke("SendMessage","Hello world", jsonObject); //pass object as json string, but it doesn't work

    Calling hubMethod from javascirpt/UI:

    customerHub.server.sendMessage("Hello world", JSON.parse(modelCustomerObject)); // Passing arguments from js client to serverHub works fine  

    Mu Customer object(entity):

    public class Customer: Entity<int>
    {
            public string Name { get; set; }
            public string Description { get; set; }
            public int Price { get; set; }
            public int AmountOrders{ get; set; }
            public string Model {get; set;}
            public bool IsActiveOrder{get; set;}
    public virtual Order Orders {get; set;} }

    Model for class Customer:

    public class CustomerModel
    {
    public string Name { get; set; }
    public string Description { get; set; }
    public int Price { get; set; }
    public int AmountOrders{ get; set; }
    public string Model {get; set;}
    public bool IsActiveOrder{get; set;}
    
    
    public CustomerModel(Customer customer)
    {
    Name = customer.Name;
    Description= customer.Description;
    Price = customer.Price;
    AmountOrders= customer.AmountOrders;
    Model = customer.Model;
    IsActiveOrder = customer.IsActiveOrder;
    } public CustomerModel() { } }


    How to pass data by "invoke" from .Net client to serverHub?

    Friday, February 26, 2016 10:19 AM

Answers

  • User61956409 posted

    Hi levivas,

    I want to pass argument "customerObject" by method "invoke" from .Net client Xamarin Mobile to serverHub.

    Please check the below link to invoke method on the server and pass complex object types parameter.

    https://components.xamarin.com/gettingstarted/signalr

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 29, 2016 5:58 AM