Hello guys and girls,
I'm used to programming mainly in Java and I'm finding it hard to find enough documention on things to get basic
functionality working. I created a simple Handler in Asp.net using C# and I'm using basically the same script
as shown in the example code they offer.
The Handler is located at:
http://www.ulrpg.com/MYSPACETEST/Handler.ashx?command=getKingdom
if you type that in as is, you'll see you get the response "Helsinc" as expected. But how do I pass that back
to my myspace app? Here is the code I am attempting to use in the script:
<script>
function init()
{
var url = "http://www.ulrpg.com/MYSPACETEST/Handler.ashx?command=getKingdom";
os_params = {};
opensocial.makeRequest(url, makeRequest_Callback, os_params);
function makeRequest_Callback(data){
var responseText = data.responseText;
alert(responseText);
}
}
init();
</script>
---------------
And here is my simple Handler code for testing purposes:
-----------------
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Text;
public class JSonDreamResponse
{
public string ErrorMessage;
public bool HadError;
public string ResponseMessage;
}
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string command = context.Request["command"];
switch (command)
{
case "getKingdom":
{
GetKingdom(context);
break;
}
default:
{
throw new ApplicationException("Command: " + command + " is not supported");
}
}
context.Response.ContentType = "text/html";
context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
}
private void WriteToOutput(HttpContext context, String output)
{
context.Response.Write(output);
}
private void WriteError(HttpContext context, string message){
}
public void GetKingdom(HttpContext context)
{
try
{
String helsinc = "Helsinc";
WriteToOutput(context, helsinc);
}
catch (Exception exc)
{
WriteError(context, exc.ToString());
}
}
public bool IsReusable {
get {
return false;
}
}
}
-------------------------------------------------------
I keep getting returned the value "undefined" in the alert box. Any help would be much appreciated.