Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Created November 9, 2012 17:50
Show Gist options
  • Save wadewegner/4047128 to your computer and use it in GitHub Desktop.
Save wadewegner/4047128 to your computer and use it in GitHub Desktop.
Call Parse Cloud Code from WinRT
var parameters = new Dictionary<string, object> { { "message", "Hello!" } };
await ParseCloud.CallFunctionAsync<IDictionary<string, object>>("sendsms", parameters);
@wadewegner
Copy link
Author

This code successfully calls the Cloud Code but ends up throwing the following exception:

System.InvalidCastException was unhandled by user code HResult=-2147467262 Message=Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'. Source=Parse StackTrace: at Parse.ParseCloud.d__0`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at App4.MainPage.d__1.MoveNext() in d:\Dropbox\Documents\Visual Studio 2012\Projects\App4\App4\MainPage.xaml.cs:line 44 InnerException:

Any insight?

@wadewegner
Copy link
Author

My bad. Missed that CallFunctionAsync defined the response object. Here's the functional code:

var parameters = new Dictionary { { "message", "Hello!" } }; await ParseCloud.CallFunctionAsync("sendsms", parameters);

@wadewegner
Copy link
Author

For those curious, this is the Cloud Code that's executing:

var message = request.params.message;
var phonenumber = request.params.phonenumber;

var twilio = require('twilio');
twilio.initialize('myAccountSid', 'myAuthToken);

twilio.sendSMS({
  From: "+12245883104",
  To: phonenumber,
  Body: message
}, 
{     
    success: function(httpResponse) {
        console.log(httpResponse);
        response.success("SMS sent!");
    },
    error: function(httpResponse) {
        console.error(httpResponse);
        response.error("Uh oh, something went wrong");
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment