Saturday, March 10, 2012

usercontext

Yes it is possible to pass an Array and refer it in the callback. Basica when sinlgle callback is used in multiple web service call the userContext is used to handle different logic.


Do you have an example of that please?


Does anyone have an example for this please?


Say I have WebService with the following method:

[WebMethod()]public string SayHello(string yourName){return string.Format("Hello {0}", yourName);}

And I am calling this method with context like the following:

function invokeWithComplexContext(){ SimpleService.SayHello('Amit', onComplete, onError, [1, 2, 3]);}And in the Callback I can access the userContext like the following:
 
function onComplete(result, userContext, methodName){ for(var i = 0; i < userContext.length; i++) { alert(userContext[i]); }}

BUT, can you access the user content on the server ?

Thats important.


No you cannot access the userContext in the server side. In that case you have to add an extra parameter in your webmethod.


So is there a way to pass data to web servics not in the params.

Maybe headers, query string, path info, etc.
mayeb even writing a soap formatter to access this state, but of course the JSON proxy must also support it.

The authentication services are obviously passing the cookie.


Certainly you can access the cookies and headers by HttpContext.Current.Request in th webmethod. And may be the authentication service doing the same. But surly not with the soap header.

No comments:

Post a Comment