Saturday, March 24, 2012

Namespace undefined in gadget

I've developed a very simple gadget. It works on my computer well. I've installed it on LiveCom and it doesn't work. I am sure I amdoing all good, as Atlas documentation writes but I get an error.

Details: on button click I call a function (as in Atlas examples):

function DoSearch()
{
MyNamespace.MyGadgetBridge.Search(.................);
}

The error is: MyNamespace is undefined.

Also of course I have

<atlas:ScriptManager runat="server" ID="scriptManager">
<services>
<atlas:servicereference path="~/HelloWorldService.asmx" />
</services>
</atlas:ScriptManager>

Defined in Gadget:

<

Scripts><atlas:scriptreferencepath="rssgadget_wt.js"/></Scripts>

and simple bridge:

<?xml version="1.0" encoding="utf-8" ?>
<bridge namespace="MyNamespace" className="MyGadgetBridge" >
<proxy type="WSWrapper, App_Code" />
<method name="Search">
<input>
<parameter name="searchKeywords" />
</input>
</method>
</bridge>

It works on my computer. I get this error only on LiveCom, why? what is wrong?

Please help. Thank you.

hello.

can you give more info on this? i haven't tried using bridges from a gadget, but i have called remote web services without any problems by using the iframeexecutor client class...


There is all info you need I think. I am not doing anything difficult. Just the most simple example gadget with brige and javascript call. You can rework Atlas example gadget from documentation to use javascript call instead of declarative for 10 min to have call like:

function DoSearch()
{
MyNamespace.MyGadgetBridge.Search(.................);
}

The error is: MyNamespace is undefined.

This error I get on LiveCom, but woks on my computer

Maybe to install the gadget on LiveCom Microsoft should "allow" my gadget or bridge work there... I do not understand this.

Also I don't understand the process of installation of gadget on LiveCom. What files are copied? How it works from there?

In the call MyNamespace.MyGadgetBridge.Search(.................);
what bridge is called, my or that was installed on LiveCom?


hello.

well, if it's undefined, then the problem is that you're not putting the correct link on the gadget...


Mr.Luis Abreu,

Can you please give me a *hint* as to how you are executing cross domain requests using IFrameExecutor class?

It would be immensely helpful if there is any documentation.

Thanks

Indo.


hello again.

well, here's a quick example i've build a couple of months ago. it uses the amazon service, which is wrapped on a "local" web service. don't forget to uncomment the iframe handler on the web.config file. here's the code (i've built it in april and haven't run in with the latest ctp):

aspx file:

<%@. Page Language="C#" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager runat="server" ID="manager" EnableScriptComponents="false" />
<atlas:Gadget runat="server"
Description="A gadget that let's you search Amazon.com."
ID="myGadget"
Title="Book Search by author name v2">
<ContentTemplate>
<input type="text" class="text" id="_txtSearch" name="_txtSearch" value="enter the name of the book you're interested in" />
<input type="button" id="_btSearch" value="Search" onclick="handleClick()" /><p></p>
<span id="t"></span>
<div id="_content">
</div>
<div id="_panel">
</div>
</ContentTemplate>
<Services>
<atlas:ServiceReference Path="AmazonHelper.asmx" />
</Services>
<Styles>
<atlas:StyleReference Path="~/cap12/livroatlasgadgetv2.css" />
</Styles>
<Scripts>
<atlas:ScriptReference Path="gadgetaux.js" />
</Scripts>
</atlas:Gadget>
</form>
</body>
</html>

js file

// JScript File
function handleClick()
{
LivroATLAS.AmazonHelper.GetBooks(
document.getElementById("_txtSearch").value,
1,
_onCallback);
}

function _onCallback( res )
{
var htmlContent = "";
var totalPages = res.TotalPages;
var currentPage = res.CurrentPage;

var books = res.BooksInCurrentPage;

for( var i = 0; i < books.length; i++ )
{
htmlContent += "<span><a target='_blank' href='" + books[i].Url + "'>" + books[i].Title + "</a></span><br /><span>" + books[i].Authors.join( "<br />" ) + "</span><p />";
}

if( htmlContent != "" )
{
document.getElementById("_content").innerHTML = htmlContent;
}
else
{
document.getElementById("_content").innerHTML = "No books found for that author.";
}

_fillPanel( currentPage, totalPages );
}

function _fillPanel(currentPage, totalPages)
{
document.getElementById("_panel").innerHTML = "";
for( var i = 0; i < totalPages; i++ )
{
var page = null;
if( currentPage != i + 1 )
{
page = document.createElement( "a" );
page.href = "javascript:;";
page.innerText = i + 1;
page.attachEvent( "onclick", _navigateToPage );
page.title = "Navigate to page " + (i + 1 );
}
else
{
page = document.createElement( "span" );
page.innerText = i + 1;
}
document.getElementById("_panel").appendChild( page );
}
}

function _navigateToPage()
{
LivroATLAS.AmazonHelper.GetBooks(
document.getElementById("_txtSearch").value,
event.srcElement.innerText,
_onCallback);
return false;
}

document.getElementById("_txtSearch").select();
document.getElementById("_txtSearch").focus();

asmx file

<%@. WebService Language="C#" Class="LivroATLAS.AmazonHelper" %>
using System;
using System.Web;
using System.Web.Services;
using Amazon;
using System.Configuration;

namespace LivroATLAS
{
public struct BookInfo
{
string _title;
public string Title
{
get { return _title; }
set { _title = value; }
}

string _asin;
public string Asin
{
get { return _asin; }
set { _asin = value; }
}

string[] _authors;
public string[] Authors
{
get { return _authors; }
set { _authors = value; }
}

string _url;
public string Url
{
get { return _url; }
set { _url = value; }
}

public BookInfo(string title, string asin, string[] authors, string url)
{
_title = title;
_asin = asin;
_authors = authors;
_url = url;
}
}

public struct TotalBookInfo
{
private int _currentPage;
public int CurrentPage
{
get { return _currentPage; }
set { _currentPage = value; }
}

private int _totalPages;
public int TotalPages
{
get { return _totalPages; }
set { _totalPages = value; }
}

private BookInfo[] _booksInCurrentPage;
public BookInfo[] BooksInCurrentPage
{
get { return _booksInCurrentPage; }
set { _booksInCurrentPage = value; }
}

public TotalBookInfo(int currentPage, int totalPages, BookInfo[] books)
{
_currentPage = currentPage;
_totalPages = totalPages;
_booksInCurrentPage = books;
}
}

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AmazonHelper : System.Web.Services.WebService {

[WebMethod]
[Microsoft.Web.Services.WebOperation(true, Microsoft.Web.Services.ResponseFormatMode.Json, true)]
public TotalBookInfo GetBooks( string author, int currentPage ) {
AWSECommerceService service = new AWSECommerceService();
ItemSearchResponse resp = service.ItemSearch(this.GetItemSearch(author, currentPage) );

if (resp.Items[0].Item == null)
{
return new TotalBookInfo(1, 1, new BookInfo[0]);
}

System.Collections.Generic.List<BookInfo> books = new System.Collections.Generic.List<BookInfo>();
foreach (Amazon.Item item in resp.Items[0].Item)
{
books.Add(new BookInfo(item.ItemAttributes.Title, item.ASIN, item.ItemAttributes.Author, item.DetailPageURL));
}

TotalBookInfo info = new TotalBookInfo(currentPage, Convert.ToInt32( resp.Items[0].TotalPages ), books.ToArray());

return info;
}

private ItemSearch GetItemSearch(string author, int currentPage)
{
ItemSearchRequest request = new ItemSearchRequest();
request.Author = author;
request.Count = "5"; //just to be safe :)
request.ItemPage = currentPage.ToString();
request.SearchIndex = "Books";

ItemSearch search = new ItemSearch();
search.Request = new ItemSearchRequest[] { request };
search.SubscriptionId = ConfigurationManager.AppSettings["AmazonId"];

return search;
}

}

}


Thanks for the reply. In one of your posts above, you said you implemented remote web services call using "iframeexecutor client class" ... Thats what I am really interested in. Basically how to do cross-domain calls from the client side without using Helper-webservice.

Any help would be appreciated.

Thanks again,

~Indo.


hello.

if i recall it correctly, there's not much into it. you just need to enable the iframecall.axd handler on the server side and you'll get the call made automatically (ie, the client side proxy will detect that you're invoking a remote web service and it'll use the handler automatically).


Hello...

I don't know if this will solve your problem, but I was receiving the same JavaScript error when implementing a bridge to call a remote web service.

The solution was as simple as adding this tag inside <microsoft.web> in web.config file:

<

webServicesenableBrowserAccess="true"/>

Hope this helps

Jaime


hello Luis

I see in your example following rows:

<atlas:Gadget runat="server"

I use MS AJAX v 1.0 b2 and I can't find this tag (I try asp:Gadget )

and second question - linkhttp://atlas.asp.net/docs/Walkthroughs/DevScenarios/gadget.aspx is not correct now. I have not found correct link :(

Please, help me. Thanks


hello.

unfortunately, gadget integration has been removed from atlas and i think it won't make it when v1.0 is out.


How I can call of web-service? should I create SOAP message?

Thanks


hello again.

as i told you in my previous mail, you cannot use the gadget control since it has been removed from the ajax extensions platform. i think that now you're supposed to use the API of live.com


It is very a pity :(
Thanks again

hello.

well, you can still use AJAX extensions in your gadget, though you do need to write more code without the gadget control.

No comments:

Post a Comment