Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

Direct method call from html event

I'm just beginning trying to get familiar with Atlas and beforehead I'm curious whether it is possible to get a event handler called without having to execute the whole state flow of a page.Hi,

do you mean a server event handler? If so, the page must go through its whole lifecycle.

Difficulty in calling web service

Hi all,

The web service which am trying to call takes two string and three array as parameters.am able to call the web service through ajaxpro.dll, but through ajax framework1.0 its not coming. the service returns response class object..pls help me out.

In .aspx page

--------------------

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="http://localhost/progressTrack21/ManageProgressTracking.asmx"/>

</Services>

<Scripts>

<asp:ScriptReferencePath="trackingScript.js"/>

</Scripts>

</asp:ScriptManager>

<inputid="Button1"type="button"value="Click here"onclick="funProgress();return false;"/>

In trackingscript.js file

----------------

function funProgress()

{

debugger;

Sys.Net.WebServiceProxy.invoke("http://localhost/progressTrack21/ManageProgressTracking.asmx","Update",false,{"UserId1":"1","PlanId1":"1","SCOId1":scoid,"ElementName1":EleName,"Value1":EleName},SucceededCallback);

}

function SucceededCallback(result, eventArgs)

{

var RsltElem = document.getElementById("Results1");

alert(result);

}

Are you getting any javascript error ??, because in your function you are directly accessing the results elements

function SucceededCallback(result, eventArgs)

{

var RsltElem = document.getElementById('<%=Results1.ClientID%>');

alert(result);

}


Hi, You do not have to call the WebServiceProxy.invoke. Instead the Ajax Framework generates a JavaScript Proxy class which represents the Server Side Web Service.

For Example if Your WebService Name is DataService and if it contains a method FetchData(), then the JavaScript class will also contain a DataService class with the FetchData Method. You can find the more info from the following links:

http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx
http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx


It is giving internal server error(500)....I tried in all possible ways...


Thank u Kazi,,,,

Monday, March 26, 2012

Design Question (Looking for your opinions)

I have a page that I need to call a method from my business tier. This method ussually will execute and complete quite quickly.

But because we are making and call to an external service. There are times where the network could be slow or the request gets sent but nothing comes back.

What I want to do is use ajax to make a call to the Business Layer. If it takes longer than say 5 secs. I want the ajax call to timeout and redirect to another page. Leaving

the process to complete on it's own (It doesn't return anything). The status of the "Async Job" will be checked somewhere else by the user.

Would this be an exceptable means of dealing with a long running task? We don't need the user to wait until it's complete.

Check out this for one example on long running queries...

http://www.west-wind.com/atlas/LongProgress/LongProgress.aspx

Maynot be exactly what you are looking for but...


That's a great example. Thank you very much.. I got it working :)

If I make the async call time out and call the function like so onTimeOut fires properly. If an error happens it goes to this method as well.

PageMethods.SendInfo(onComplete,onTimeOut);

If I make the async call error out OR time out and call the function like so PageMethods.SendInfo(onComplete,OnError,onTimeOut); both

timeouts & errors got the onError method.

Deserializing JSON objects manually - should I be doing this?

OK, I'm probably doing something horrendously wrong here, but here goes.

Following on from my battle with attempting to getembedded javascript to call an embedded web service I have got to a certain point and realised something may well be going wrong somewhere. I am intercepting calls to my web service usign a custom IHttpHandlerFactory. I am dealing with these calls using a custom IHttpHandler. I am talking back to the javascript by callingcontext.Response.Output.Write(...). (Correct me please if I'm doing anything wrong). Is there anyway to access the deserialized array of arguments passed to the web service? I can get the string passed from the javascript by analysingcontext.Request.InputStream.


So, given a"Person" class of:

class Person
{
string _name;

public string Name
{
get { return _name; }
set { _name = value; }
}
}


And aweb method of:

[WebMethod]
public Person ChangeName(Person p)
{
...
}


And ajavascript call of:

var person = new Person();
person.Name = "Josh";
MyWebServiceClass.ChangeName(person);


Thecontext.Request.InputStream is:

{"__type":"Person","Name":"Josh"}


If I try:

Person p = JavaScriptSerializer.DeserializeObject("{\"__type\":\"Person\",\"Name\":\"Josh\"}");

I get an argument null exception.


If I so much as change "__type" to "_type", I get a nice name-value collection.


If I change the string to remove the "__type" altogether and try:

Person p = JavaScriptSerializer.Deserialize<Person>("{\"Name\":\"Josh\"}");

I get a nicely deserializedPersonobject. But this involves messing with the InputStream, which I don't reckon I should have to be doing.

Any suggestions?

Cheers all,
Josh

Well, just as an update, I've discovered the way AJAX.NET deals with this deserialization is using a class called JavaScriptObjectDeserializer, which is now internal but I believe used to be public (seehttp://www.hanselman.com/blog/default.aspx?date=2006-07-07). I must be doing this wrong, can anyone give me any clues? Can I just return an instance of my web service in my HttpHandlerFactory somehow so I give it back to AJAX.NET to deal with I just "route" it to the right place? Please help!!!


I believe that this tutorial is a good resource for you:http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

I didn't test it myself, but you could add a callback function to your code that invokes the web service, set the user context with the object you want to access it and then implement this callback function.

Hope this helps,

Maíra


Hi Maíra!

Thanks for the link! I'm not sure if this helps me out in my specific situation, but I might be wrong; I am not having the web service invoked under normal circumstances; I am intercepting a call (with my HttpHandler) for an "asmx" file that doesn't actually exist and trying to pass that call on the the relevent web service that is embedded within my dll. Maybe I don't understand what exactly is meant by setting the "user context", though - this sounds like it could be of help to me.

Thanks again,
Josh

Wednesday, March 21, 2012

Delegates on succes webservice call

Hi All,

I am writing a control where i would like to refer to a method inside my own control, see code below to make the situation clear:

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,this.WebserviceCallCompleted,this.WebserviceCallFailed,null, 10000);

First i do a webservice call which is working great! As you can see when the call succeeds the function WebserviceCallCompleted is invoked. In this method i would like to set a variable and start the rendering proces again. I do this with:this.Render;

WebserviceCallCompleted:function(result)

{

this._buttonText = result;

this.Render;

}

When i run this code the Render method isn't invoked. any ideas? should i use delegates?

Thanks in advance!

Regards,

To Resolve the this keyword use Function.createDelegate. Like:

var successHandler = Function.createDelegate(this, this.WebserviceCallCompleted);

var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false,null,successHandler,this.WebserviceCallFailed,null, 10000);


Hi KaziManzurRashid,

Thanks for your reply. I implemented your solution but it isn't working (yet) below you see what i have done:

InvokeWebservice:function()

{

var _completeHandler = Function.createDelegate(this,this.WebserviceCallCompleted);var webRequest = Sys.Net.WebServiceProxy.invoke('Webservice/ImageService.asmx','Hello',false, {"test":$get('txtfld1').value}, _completeHandler,this.WebserviceCallFailed,null, 10000);

}

,

WebserviceCallCompleted:function(result)

{

this.Render;

}

The WebserviceCallCompleted method is invoked so the delegate is implemented right. When i take a closer look at the this instance is see that 'this' is representing the right control and it contains a Render method but it still isn't invoked. Any idea?

Regards,


I could not find any reason the Render is not get executed, may be you should put this.Render() instead of this.Render.


hi KaziManzurRashid,

Very stupid but thats the trick i changed this.Render in this.Render() and it works. Probably there is a difference when you refer to a method when creating a delegate and when refering directly to it. I feel a little stupid! Thanks for your time and solutionBig Smile

Regards,

Delayed GridView Loading

I have a GridView that is loading data from a web service. For each item in the table a call must be made to the web service and they are averaging around a half second per call. So for a GridView with 83 rows it takes around 41 seconds to load the page the first time. After the page is initially loaded the data is cached so it doesn't take nearly as long. What I'm wondering is if there is a way that I could show the user the rest of the page and then load the GridView via Atlas once the rest of the page loads so that the user can at least see the page is loading and doing something? Icing on the cake would be to be able to display a loading gif while the GridView is loading.

Thanks,

Eric

Hello, I think using an UpdatePanel control will make things better.

A.

Declarative WebService call

Hi everybody

I just tried to call a method with MS-Ajax and the xml-script ... but in some way it doesn't work ...

This is the code:

-----------


<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<label id="LbTest" /
<button id="BtTest">
<click>
<setPropertyAction target="LbTest" property="text" value="TestStarted" />
<invokeMethodAction target="CFCCall" method="invoke">
<parameters userContext="" />
</invokeMethodAction>
</click>
</button
<serviceMethodRequest id="CFCCall" url="Services/SCheck.asmx" methodName="Test.Web.CheckClass.Check">
<completed>
<setPropertyAction target="LbTest" property="text" value="TestCompleted" />
</completed>
<error>
<setPropertyAction target="LbTest" property="text" value="TestError" />
</error>
</serviceMethodRequest>
</components>
</page>
</script>

-----------

I got a check method in my checkclass in the webservice, which is in the namespace "Test.Web".

If I call this with JS directly, I'm getting my result - but if I'm doing it this way - I just get the "TestError" label-value. Any ideas?

Found the problem: It was the webservice - The webservice denies by default GET requests... does anyone know how I could switch the default method in xml-script to POST (i can't enable GET in the webservice, because I don't have access to it)... Or does someone know how I can call a Javascript in XML-script? Because with an JS I could make call and tell the call to use POST...