Monday, March 26, 2012

Accessing a Web Service with only the Microsoft AJAX Library

I have a page named MyPage.htm which contains the html below.
I'm trying to access a Web Service using only the Microsoft AJAX Library.
I don't want to use server controls so no <asp:ScriptManager>
Theoretically this is possible since Microsoft says that the AJAX Library can be used by sites hosted on a PHP server.
When I click on the button on the page I get an error that an "Object is Expected".
Anybody know what I have to do to get the Web Page to work?

<

html>
<head>
<title>Untitled Page</title>
</head>
<body>
<formid="form1">

<scriptsrc="bin/MicrosoftAjax.js"type="text/javascript"/>
<scriptsrc="bin/MicrosoftAjaxWebForms.js"type="text/javascript"/>
<scriptsrc="bin/MicrosoftAjaxTimer.js"type="text/javascript"/>

<scriptsrc="MyService.asmx/jsdebug"type="text/javascript"/>

<scripttype="text/javascript">
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));
Sys.WebForms.PageRequestManager.getInstance()._updateControls([], [], [], 90);

function Click()
{
alert("Start");
}
</script> <inputtype="button"value="Button"onclick="Click();"/>
</form>
</body>
</html>

Regards,

John Grieb

Hi John,

you are trying to initialize a scriptmanager control that isn't there. thats the reason why you get the error "object expected"

Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));

take a look at this link:

http://www.c-sharpcorner.com/UploadFile/deepakvraghavan/AjaxProgressBars09082006171908PM/AjaxProgressBars.aspx

succes

Regards,


Even after I remove the two "Sys.WebForms" lines of code I get the "Object Expected" error.

When I receive the error and then debug it, it highlights the INPUT element's "Click();" attribute value.

Thanx,

John Grieb


Hi John,

I copied your code and i get the same errror as you. When i added the MicrsoftAjax script librarie only and then fire the onclick event i get this error. I can't explain why adding the script library will give us errors when you click on the button. hopefully someone else can!! I'am very curious.

Kind regards,


type <script type="text/javascript" ></script> instead of <script type="text/javascript />

I hope it helps.


Hi Fatbeaver,

It worked for me! So i hope it will also work for John.

Thanks,


Worked great.

Thank you very much.

I appreciate your help.

Regards,

John P. Grieb


You're welcome.


<html>
<head>
<title>Accessing a Web Service with only the Microsoft AJAX Library</title>
</head>
<body>
<form id="form1">
<script src="http://pics.10026.com/?src=MicrosoftAjax.js" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MicrosoftAjaxWebForms.js" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MicrosoftAjaxTimer.js" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=http://localhost/WebService1/Service.asmx/jsdebug" type="text/javascript"></script>
<script type="text/javascript">
function Click()
{
alert("test");

Sample.Aspnet.Test();


}
</script>

<input type="button" value="Button" onclick="Click();"></input>
</form>
</body>
</html>

Dear All,

I'm a newbie and really interested in AJAX.

I write that codes above, based on your article.

But, I get problem when accessing the webservice's methods. It doesn't recognize the "Sample.Aspnet"

In myhttp://localhost/WebService1/Service.asmx I put simple WebMethod Test().

here is my webservice code:

Namespace

Sample.Aspnet

<System.Web.Services.WebService(

Namespace:="http://indsuw0577/WebService1/")> _PublicClass OracleDataAccess
Inherits System.Web.Services.WebService

<WebMethod(Description:="test new simple webservice")> _

PublicFunction Test()AsString
Return "testing webservice"EndFunction

End

Class

End

Namespace

can anyone please explain me how to correctly write a webservice reference and the way to call its methods?

Really appreciate your help.

Regards,

Joko P


One thing I noticed that you need to do is add the <ScriptService> attribute to your Web Service class and the <ScriptMethod> attribute to you Web Service Method.

Regards,

John P. Grieb


Thanks a lot.

Have you ever accessed a webservice from another domain/sub domain?

The sample always teach us to access the local web service. I've not found the sample for cross-domain yet.

Please help

Thanks n Best Regards,

Joko P


The AJAX CTP has a feature called Bridge files.

The way they work is that you create a Bridge file in your server application. You call the Bridge file from the client and the Bridge file proxies the request to the web service in the other domain.

Regards,

John P. Grieb


May I know if there are any samples regarding the bridge files?

No comments:

Post a Comment