MySpace Developer Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Help Me Out Here

Last post 05-14-2008 6:17 PM by HeX. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-14-2008 5:50 PM

    • HeX
    • Not Ranked
    • Joined on 05-13-2008
    • Posts 5

    Help Me Out Here

     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. 

     

  • 05-14-2008 6:17 PM In reply to

    • HeX
    • Not Ranked
    • Joined on 05-13-2008
    • Posts 5

    Re: Help Me Out Here

    Well after spending all day, I finally started to figure things out and now I have it responding properly.

    I found an excellent site that is descriptive and well written at: 

    http://code.google.com/apis/opensocial/articles/makerequest.html 

     

    The solution is to do something like the following:

    <script>
    function init()
    {

    function makeRequest(url) {
      var params = {};
      params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
      gadgets.io.makeRequest(url, response, params);
    };

    function response(obj) {
      alert(obj.text);
    };
    makeRequest("http://www.ulrpg.com/MYSPACETEST/Handler.ashx?command=getKingdom");
    }
        init();
    </script>   

Page 1 of 1 (2 items)