Sending parameters to client in Photon v3

Options
emreCanbazoglu
edited October 2011 in DotNet
Hi there,

We couldn't send any parameters to the client with SendOperationResponse.

Here is the code we use when generating the response. I think we make mistakes when using SetParameter method. I tried some other implementations but no difference. I get 0 parameters in the client side. In v2 I think hastables are used but in v3 dictionary should be used to set parameters
       private void HandleKeywordRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {

            Dictionary<byte, string> opParams = new Dictionary<byte, string>();

            opParams.Add((byte)100, "hello");

            OperationResponse or = new OperationResponse();

            or.SetParameters(opParams);

            this.SendOperationResponse(or, sendParameters);     
        }

Comments

  • Boris
    Options
    Hi, you forgot to set the OperationCode of the response that you are sending.
  • Boris
    Options
    Oh, I just noticed that you use "SetParameters" - the parameter is a "contract" object, not a dictionary.
    use "or.Parameters = opParams" instead.
    You could also define a class like this
    class TestResponse {
    [DataMember(Code = 100)]
    public string Hello {get;set;}
    }
    

    and then
    var contract = new TestResponse { Hello = "hello" };
    var response = new OperationResponse(request.OperationCode, contract);
    this.SendOperationResponse(response, sendParameters);
    
    or
    var contract = new TestResponse { Hello = "hello" };
    var response = new OperationResponse();
    response.OperationCode = request.OperationCode;
    response.SetParameters(contract);
    this.SendOperationResponse(response, sendParameters);
    
  • How about:
    var response = new OperationResponse(100);
    response.Parameters = new Dictionary<byte, object>{{1,"hello"}};
    SendOperationResponse(response, sendParameters);
    

    If you want to go the contract-free route?
  • Boris
    Options
    Yep, looks good.