Sunday, March 11, 2012

Web Service Result

Hi Ivan,

The response should be directly in a string if everything is set up right,i.e., alert(result) should give you "Hello World".
Are you using the same sample as shown in the tutorial "Calling Web Services from Client Script in ASP.NET AJAX" (http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx)? Did you change something in your code? I think it would help if you post the code that you're using to invoke the web method.
What is the content of the XML response?

Regards,

Maíra


Maira, Thanks for your comment!!!!

I am trying to use the WebServiceProxy class which allows me to set service URL at runtime. It is pretty straight forward, however as i described before at endthe result divcontents are:

[object]

Here is a sample aspx:

<%

@.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title><scriptsrc="WebServiceProxy.js"language="javascript"type="text/javascript"></script>

</

head>

<

body><formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/><div></div><inputtype="button"onclick="HelloWorld();"value="WebService Test1"/><p><spanstyle="background-color:Aqua"id="ResultId"></span></p></form>

</

body>

</

html>

Here is the JS file:

// JScript File

var

webMethod ="HelloWorld";

var

webServicePath ="http://localhost/testservice/service.asmx" ;

//var webServicePath = "~/test/service.asmx" ;

// This function shows how to use the

// WebServiceProxy.invoke method without passing

// parameters.

function

HelloWorld()

{

// var sAlertString = ""

// sAlertString +="\nSys " + Sys;

// sAlertString +="\nSys.Net " + Sys.Net;

// sAlertString +="\nSys.Net.WebServiceProxy " + Sys.Net.WebServiceProxy;

// alert(sAlertString);

Sys.Net.WebServiceProxy.invoke(webServicePath, webMethod,

false,{}, OnSucceeded, OnFailed,null, 5000);

}

// This is the callback function invoked

// if the Web service succeeded.

function

OnSucceeded(result, eventArgs)

{

//test lines here: //runtime values//alert(result); //[object]//alert(result.xml); //actual xml response//alert(result.documentElement); //[object]//alert(result.documentElement.childNodes[0].text); //HelloWorld

// Display the result.var RsltElem = document.getElementById("ResultId");

RsltElem.innerHTML = result;

}

// This is the callback function invoked

// if the Web service failed.

function

OnFailed(error)

{

// Display the error.var RsltElem = document.getElementById("ResultId");

RsltElem.innerHTML =

"Service Error: " + error.get_message();

}

if

(typeof(Sys) !=="undefined") Sys.Application.notifyScriptLoaded();

Thanks again for your comments!

Ivan


OK,

To begin with i stared using the WebServiceProxy class and i was experiencing the above problems.

I just tried it using the scriptManager like this:

<

asp:scriptmanagerID="Scriptmanager1"runat="server"><Scripts><asp:ScriptReferencePath="Test.js"/></Scripts><Services><asp:ServiceReferencePath="TestService\service.asmx"/></Services></asp:scriptmanager><inputtype="button"onclick="HelloWorld1();"value="Test"/>this is working just fine... However, the web service location is given at design time which in my case does create some limitations...

So it is either that i am not using the WebServiceProxy properly, or it must be a bug that it returns XMLDom object vs JSON.

Has anyone experienced similar issues with the WebServiceProxy class?...

Thanks,

Ivan


maira.wenzel:

Hi Ivan,

The response should be directly in a string if everything is set up right,i.e., alert(result) should give you "Hello World".
Are you using the same sample as shown in the tutorial "Calling Web Services from Client Script in ASP.NET AJAX" (http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx)? Did you change something in your code? I think it would help if you post the code that you're using to invoke the web method.
What is the content of the XML response?

Regards,

Maíra

Maira,

I have been running tests and this is what my findings are:

Using the WebServiceProxy class,

if I call a web service which is underneath the application directory things are working just fine.

For example, if my application is at http:\\localhost\testapp\test.aspx and the service is at http:\\localhost\testapp\myservice\service.asmx, this works as expected..

HOWEVER,

if the web service is NOT under the web application directory, it does NOT work. In such cases, the result looks like is DMLDom object...

Example: application is at http:\\localhost\testapp\test.aspx and the service is at http:\\localhost\myservice\service.asmx - this DOES NOT WORK, it is same service, same application, same code...What gives?...

Thanks for any feedback?..

Ivan

No comments:

Post a Comment