Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Wednesday, March 28, 2012

Calling Asynchronous Web Services

How do I call an asynchronous Web Service, from AJAX, that has been defined according to this article:

How to: Create Asynchronous Web Service Methods

The AJAX Web Service proxy-generator creates Begin<MethodName> and End<MethodName>... methods instead of just <MethodName>.

Best Regards,
Michael Carr

1. On your web service class, place the attribute of [ScriptService]

2. Create your web method.

3. Call your web method from javascript at the following syntax:
<YourWebServiceName>.<YoureMethodName>(<parameter1>,<parameter2>,...,onSuccess, onError)
where onSuccess and onError are javascript functions acts as a callbacks to the web method. (you don't have to place
an onError callback however it is recommended)

4. Your onSuccess function shold receive your method returned value as a parameter and should look like that:
function onSuccess(result)
{
//Handle the method's returned value
}



Vinija, that's fine for "normal" web service methods, but I'm trying to call an asynchronous web service method as defined by the above-referenced document. In this case, the WSDL describing the method is <MethodName>, but the AJAX WebServiceProxy generated class creates only Begin<MethodName> and End<MethodName> stubs. So, your approach doesn't work in this case.


The question is, what is the purpose of making an asynchrnous call?

My approach describes an asynchronous call to web service from javascript (If it wasn't asynchronous there wouldn't be any
callbacks).

If the web service is remote and you need to create a proxy to it, all you have to do is copy the method names without
any prefixes and call the same method on the remote service from your copied method. Then you can add the [ScriptService]
attribute and call it from AJAX,

The above reference doesn't relate to AJAX but to regular asynchronous call. To do that you need to place two calls
for begin<Method> and end<Method> while calling the end<Method> will be in fact synchronous (you have to wait
for the method to end). However, If you don't want any responce, you might just call the begin<Method>, However,
toperform asynchronous calls from AJAX you realy don't need an "asynchronous proxy".


Ajax itself is Async, There is not benifit of creating that kind of WebService.


When using asynchronous web services does the "work" move to a new background thread or does it still remain on an ASP.NET thread? (A similar pattern to using an IHttpAsyncHandler.) If it does move to a non-ASP.NET thread then that would be a good reason to use the asynchronous web service pattern, even though AJAX is an asynchronous pattern as it provides scalability for the website because ASP.NET has a limited number of threads available.

But, again, I'm not sure if the work moves to a background thread in the asynchronous web service model.

Happy Coding.


Yes Rumerman you're exactly right. Somehow I wasn't able to convey that point in my earlier posts.Sad I think the earlier posters are perhaps confusing anasynchronous method (what I want to do) with anasynchronous call to a method (what they're describing). I am basically trying to implement for a web service (asmx) what the "Async" property of the @.Page directive implements for web forms (aspx).


I got ya... but there's no way to do it Sad

The RESTHandler that handles our request when we execute a client call to a web service method we've tagged as a ScriptMethod is synchronous. It implements IHttpHandler, not IHttpAsyncHandler.

I've gotten different responses from MSFT regarding why this is the case, but it seems that the consensus was that since the next version of ASP.NET AJAX supports calling WCF methods and those don't have to use ASP.NET threads anyways (they can live at an arbitrary endpoint not on the ASP.NET stack), then there wasn't a need to implement the RESTHandler using IHttpAsyncHandler because it would scale without moving the work to a background thread ... Now, my response to MSFT was, "wasn't WCF out before ASP.NET AJAX 1.0 dropped? (Yes.) Then why wasn't WCF supported to begin with?" Still waiting on an answer for that ... but most likely it'll be the so many features, so little time answer, which as a developer in the corporate world, I understand, even if I think this was a big missing feature.

So to answer your question, no, there is no direct exposure to the BeginWebMethodName, EndWebMethodNamethat you're asking about.


My understanding from the document I referenced in the first post of this thread was that asynchronous web methods are basically a server-side construct that provides a framework within which you can return a thread to the pool until some long-running process completes. Since this framework is established/handled within the server, it should have no bearing (I would suspect) on how the client calls the method. In fact, if you look at the WSDL created for the web service described in that document (or point your browser at webservice.asmx), you'll see that the WSDL has only <MethodName> defined and not Begin<MethodName> and End<MethodName>. This suggests to me that the client should see only <MethodName> and call it as it would any other web method.

I suspect that what's happening in this case is that AJAX's proxy-generating code is using reflection to get the web methods instead of WSDL, and as a result it's creating Begin<MethodName> and End<MethodName> when it should be creating only <MethodName>. If this is the case, fixing this behavior may be as simple as fixing the proxy-generating code to detect Begin<> and End<> methods (as the WSDL-generator does, evidently) and handle them accordingly.


korggy:

... asynchronous web methods are basically a server-side construct that provides a framework within which you can return a thread to the pool until some long-running process completes.

That's absolutely correct. Only MethodName is in the WSDL, and the handling of the Begin<MethodName> and End<MethodName> requests is done by an implementation of the IHttpAsyncHandler. When AJAX interrogates the web methods (using reflection, you are correct), it only sees the WebMethod, not the Begin/End version of the WebMethod. There are no Begin/End methods exposed to the client as REST callable methods. Since ASP.NET AJAX overrides the default Handler for web service methods when they come across in a REST format and doesn't use the built-in .NET WebServiceHandler (handler for *.asmx), the asynchronous capabilities of the WebServiceHandler (the ability to handle Begin* and End*) aren't available. Even if we fixed the proxy to spit out Begin* and End* methods, the RESTHandler wouldn't know what to do with those calls and would just look for a web method of that name.


I have the exact same issue. We are making a call to a web service that in some cases has to start a process that can take a few seconds to complete. With the high volume we are handling keeping that ASP.Net thread locked is not an option so we moved to an Async Web Method model. The problem is that everything works perfectly find when you use XML as the return type, as soon as you move to the JSON serialization you get a method not found when you look for MethodName. We are using jQuery to create the web service calls, so in this case we are using XML until we can get around the problem with JSON.

Calling a Web Service that requires parameters in a SOAP Header

Is calling a web service that requires parameters in a SOAP header supported? What is the best way to try and accomplish this?

SOAP is not used in the exchange between client and server, instead JSON is used.

JavaScript Object Notation (JSON) is a lightweight client-server data exchange format. It is used as an alternative to data exchange with XML in AJAX, with the advantage that it can be parsed much more easily than XML. For example, in JavaScript, JSON objects can be deserialized by simply passing them to theeval function.

For more information, see the beta documentation at:http://ajax.asp.net/docs/Overview/intro/async/default.aspx

Calling a Web service method that returns an XmlDocument object

I'm calling a webservice method that returns an XmlDocument object. I'm getting the result back object back, but in my SuccededCallback function I'm having trouble navigating through the object with JavaScript. I'm trying to use methods on the object like .selectsinglenode and .selectnodes etc, but I keep getting a script error; "Object doesn't support this property or method. Any ideas? I'll post some of the code i'm trying to work with below.

Here is how i call the method from the client ...

Navegate.Services.GeneralTasks.GetSelectedPartyNumber(guid, id, SucceededCallback, FailedCallback);

Here is the web method ...

<WebMethod()> _

<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _

PublicFunction GetSelectedPartyNumber(ByVal sessionguidAsString,ByVal idAsInteger)As XmlDocumentDim oXmlDocumentAs XmlDocument

oXmlDocument =

New XmlDocumentWith oXmlDocument

.LoadXml(

"<DocumentPacket><Company><Number>12345</Number></Company></DocumentPacket>")EndWithReturn oXmlDocument

EndFunction

And here is how i handle the response from the webservice method but get an error on .selectsinglenode ...

function

SucceededCallback(result)

{

alert(result.selectsinglenode(

"DocumentPacket/Company/Number").text);

}

Umm... Since it took five hours for this to post i was able to find the solution elsewhere.

I worked after I user .selectSingleNode instead of .selectsinglenode.

Calling a web service in a javascript causes page reload

Hey guys,

Here is what is happening. I have a user control in which I have an update panel with a button and some label. On click of that button, I call a javascript function which in turn calls a web service. The web service does get called and everything works nicely, but the whole page is being refreshed. The moment the javascript calls a web service, the refresh of the whole page occurs (when in turn nothing should happen besides the web service called).

Do I have something misconfigured that causes the script manager to do the whole page refresh on a web service call? I have the same structure in another control, and that one doesn't cause the page refresh.

If anyone has experienced this and have a solution for it, I would love to hear it.

Thanks!

Are you using Server Button Control(<asp:Button/>) of usual html button(<input type="button"> ?

I'm assuming you have something like:

<asp:Button ... OnClientClick="CallMyWebService()" />

or

<input type="button" ... onclick="CallMyWebService()" />

Try making it "CallMyWebService(); return false;"... the "return false" tells the browser not to continue handling the event (by submitting the form, for example). If that's not it, you might try showing us your code.

Calling a Web Service from within JavaScript source

I'm trying to make an internal Web Service call from within an ATLAS client control, but I can't figure out how to get the parameters passed into the call properly into the Invoke method for ServiceMethod.

The following manages to call the Web Service but the parameter is not respected.

var num =new Object();

num.Value = -1;

var serviceMethod =new Sys.Net.ServiceMethod(_serviceURL, _serviceMethod,null/*? _appUrl */);var _request = serviceMethod.invoke(num, _onMethodComplete, _onError,

_onError,_onError,

this,

2000, Sys.Net.WebRequestPriority.Normal);

Actually I can see that the object needs to be formatted with the name of the parameter. While I can do this for testing - at runtime I have no idea what service the user is connecting to so I won't know the name of the parameter. Isn't there some more generic way to call the Web Service from code?

Also what is AppUrl in this context?

I suspect the answer is the higher level ServiceMethodRequest, but it takes a UserContext object that I have no idea how to create.

Any ideas appreciated.

+++ Rick --

The first parameter to invoke() is an object that wraps all the parameters of your server method. e.g if your server method takes an int named 'n' and a string named 's', you would have:

serviceMethod.invoke({i:5, s:"Hello"), ...)

David


Ok, that's not terribly useful <g>... All of the values passed are going to be variables. Unless I parse this myself I can't see how to call the service dynamically with this scheme.

There's gotta be a higher level mechanism for making a remote Web Service call? If not, then that's something that should maybe be there? Similar to what Callmethod used to do?

+++ Rick --


Not sure I'm following you. In the code above, you can replace 5 and "Hello" by arbitrary variables.

Note that there is indeed an alternative way of calling services by using the generated proxy. See thispage for an example.


Yeah of course I can call a Web Service that's PREDEFINED using the proxy class generated, but that doesn't help if you need to call the service when you don't know beforehand what the name is or what's exposed on it. If you want dynamic execution you won't know immediately at runtime what the parameters are or what the type.

So yeah, I can write a string value there but if I don't know that it's a string beforehand it gets to be a major hassle to write that call.

Consider this scenario: You build a custom client control and you have an option to call a service Url with arbitrary parameters that are set up in an array. Then you have to parse that call into this funky syntax.

There needs to be a way to dynamically call a service the same way that CallMethod used to work.


Yeah of course I can call a Web Service that's PREDEFINED using the proxy class generated, but that doesn't help if you need to call the service when you don't know beforehand what the name is or what's exposed on it. If you want dynamic execution you won't know immediately at runtime what the parameters are or what the type.

So yeah, I can write a string value there but if I don't know that it's a string beforehand it gets to be a major hassle to write that call.

Consider this scenario: You build a custom client control and you have an option to call a service Url with arbitrary parameters that are set up in an array. Then you have to parse that call into this funky syntax.It doesn't work.

There needs to be a way to dynamically call a service the same way CallMethod used to work. So you can specify an array of values, an endpoint Url and method name.


I do not think Macrh CTP directly provides the functionality you are looking for. But if you can exam how Sys.Data.DataSource class works. it may provide some hints if you decide to write you own class to accomplish your goal.

Actually, the syntax above is completely generic, and requires no hard coded knowledge of any aspect of the web service. All the parameters are passed as arbitrary name/value pairs on a standard Javascript object, which can be added dynamically.

David


David, I think your sample code is some kind of generic, but i don't see how it works if we don't know , at design time, what public web services out there user want to call.


Why do you think you need to have this information at design time? Every piece of the code (the URL, the method name, the parameter names and values) can be specified dynamically.

Of course, if you are referring to the proxy class, then yes, that is only usable for the case where you know at design time what service you want to call. But the original post was not about the proxy.

David


Hi David,

We seem to have some sort of disconnect here. Let me explain what I mean.

You said:

The first parameter to invoke() is an object that wraps all the parameters of your server method. e.g if your server method takes an int named 'n' and a string named 's', you would have:

serviceMethod.invoke({i:5, s:"Hello"), ...)

First is that type prefix required or not? I think I tried without it and it didn't seem to work. If it is required then the above is not generic because you'd have to parse the values into the above format and then eval it into a string somehow which is a mess.

You say the above with such certainty, but you have to remember we're working off this stuff blind. This stuff isn't documented. We DON'T KNOW what the parameter signature is, we have to guess...

So anything you can do to explain would be really helpful...

Thanks,

+++ Rick --


Hi Rick,

In Javascript writing { i:5, s:"hello" } creates an object that contains two fields with those name/value pairs. 'i' and 's' are not prefixes, they are field names, and in Atlas JSON services (as in SOAP) they are required since parameters are passed by name (and not by order).

Another way to create this same object is to write:

var o = {};
o.i = 5;
o.s = "hello";

And yet another way which I think will be the one you want is:

var o = {};
o["i"] = 5;
o["s"] = "hello";

Note that that there is no need to call eval(), which would indeed be ugly (and inefficient). Does that give you what you are lookin for?

And I certainly realize the doc is poor and samples are limited. But they'll get better! :)

David

Calling a web service from javascript at page load

I need to call a web service at page load from javascript. I have several other web services that are successfully called on other occasions (when leaving a text input field for example).

I suspect the reference by the script manager to the services aren't done at the moment of the call (when the page load). The service is working fine when called from another "event handler" i.e. whenever input events are fired. Also, any service I try to call at page load failed to be called.

So, do I guess right? What can I do to get my call to work?

I'm using April CTP

Thank you all in advance

Check thishttp://atlas.asp.net/docs/atlas/doc/services/exposing.aspx

look for Calling Web Services When a Page Loads, hope this helps.


Thank you very much... I should have look twice in the documentation

The documentation doesn't exist anymore, and the trick it suggested no longer works on Beta 2:

<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
<application id="application" load="OnApplicationLoad" />
</components>
</page>
</script>

What's an alternative way to do this besides using setTimeout to wait some arbitrary number of seconds before calling that javascript function "OnApplicationLoad"?

Calling a Web Service from Javascript

Hello!

I'm developing a WebTv channel using Atlas. My problem is in the calling of the Webservice from Javascript, it only works when I put one button like in the Atlas example:http://atlas.asp.net/docs/atlas/samples/services/Simple.aspx

The error appears when I'm invoking the WebService on the 'onload' event of the page:

requestSimpleService = iDomus.RSS..RssParser('http://www.maisfutebol.iol.pt/rss.php',OnComplete, OnTimeout);

The error on the 'onload' event is: Microsoft JScript runtime error: 'iDomus' is undefined.

I suspect that the namespace is not recognized because the Atlas engine is rendered after my script.

Any help will very appreciated.

Best regards,

Paulo Alves.

not that i have any answer for this but...

do you have "Type.registerNamespace("iDomus")" any where in your javascript?
better yet... is it before the actualy class (or object) decleration:

<script type="text/javascript">
Type.registerNamespace("iDomus");
iDomus.RSS=function(){
...
}
</script>

The other problem is that you might not have the "Namespace" setup correctly... so if your object is actually "iDomus.RSS.RssParser" then I would register the "iDomus.RSS" Namespace

since I'm working blind with what the page setup looks like...
it could also be that your object decleration is further down in the code than in the "onload" event.

again... i'm not apart of any "team" so... take it for what it is worth:
declare all of your objects first and then utilize the "pageLoad" function that gets called from Atlas

-- page declare
-- html
-- head
-- -- script manager
-- body
-- -- html elements
-- end body
-- script [for atlas]
-- -- js objects
-- -- pageLoad(){}
-- end script
-- end html

this way if you have the a seperate JS file then the "Script Manager" should load the JS file before the "pageLoad" or before the lower script section gets parsed by the browser

hope that helps...


Hellomeisinger!

Thank you for your reply.

The namespace I think is registered by the ScriptManager. When I invoque the webservice: Rss.asmx/js the result is:

Type.registerNamespace('iDomus'); iDomus.RSS=new function() { this.path = "http://localhost:4360/WebTV/RSS.asmx"; this.appPath = "http://localhost:4360/WebTV/"; var cm=Sys.Net.ServiceMethod.createProxyMethod; cm(this,"RssParser","url"); }

My aspx has the follow code:

<%

@.PageLanguage="C#"AutoEventWireup="true"CodeFile="SimpleRSS.aspx.cs"Inherits="aluno_Media_player" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<headrunat="server">

<title>WebTV.ESTIG</title><linkrel="stylesheet"href="default.css"type="text/css"/>

</

head><atlas:ScriptManagerID="scriptManager"runat="server"EnableScriptComponents="true"><Services><atlas:ServiceReferencePath="RSS.asmx/js"/></Services></atlas:ScriptManager>

<

bodytopmargin="0"leftmargin="0"rightmargin="0"background="images/ban5.jpg"><formid="form1"runat="server"><divid="Publico"class="PainelWebTV"></div>

<

scripttype="text/javascript"language="JavaScript">//timer = window.setInterval('parser();',1000);

parser();

function parser()

{

//Call script proxy passing the input element data

requestSimpleService1 = iDomus.RSS.RssParser(

'http://www.publico.clix.pt/rss.asp?idCanal=10'

,

//params

OnCompletePublico,

//Complete event

OnTimeoutPublico

//Timeout event

);

window.clearInterval(timer);

timer = window.setInterval(

'parser();',10000);returnfalse;

}

function OnCompletePublico(result)

{

Publico.innerHTML = result;

}

function OnTimeoutPublico(result)

{

Publico.innerHTML =

"Offline.";

}

</script></form><scripttype="text/xml-script">

<page xmlns:script=

"http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</

body>

</

html>

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

And the WebService:

<%

@.WebServiceLanguage="C#"Class="iDomus.RSS" %>

using

System;

using

System.Web;

using

System.Collections;

using

System.Web.Services;

using

System.Web.Services.Protocols;

using

System.Text;

using

System.Text.RegularExpressions;

using

System.Xml;

using

System.Net;

using

System.IO;

namespace

iDomus

{

[

WebService(Namespace ="http://idomus/")]

[

WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]publicclassRSS : System.Web.Services.WebService

{

[

WebMethod]publicstring RssParser(string url)

{

string title =null;string link =null;XmlTextReader reader =null;StringBuilder sb =newStringBuilder();

reader =

newXmlTextReader(url);

reader.MoveToContent();

if (!reader.EOF)

{

reader.MoveToContent();

int cont = 0;while (reader.Read() && cont < 4)//processa o ficheiro RSS

{

if (reader.Name =="item" && reader.NodeType ==XmlNodeType.Element)

{

sb.Append(

"<img src=\"images/bullet.gif\"> ");

}

if (reader.Name =="title")

{

title = reader.ReadString();

}

if (reader.Name =="link")

{

link = reader.ReadString();

}

if (reader.Name =="item" && reader.NodeType ==XmlNodeType.EndElement)

{

sb.Append(title);

sb.Append(

"<br />");

cont++;

}

}

sb.Append(

"<small>(act. " +DateTime.Now.Hour +":" +DateTime.Now.Minute +")");

}

return sb.ToString();

}

}

}

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

As you said, maybe the code is not in right place, but I don't know another option.

Sorry for the length of the post and thank you again for your help.

Regards,

Paulo Alves.


The Javascript error is:

Microsoft JScript runtime error: 'iDomus' is undefined

In Fiddler the error is:

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

System.Web.HttpMethodNotAllowedHandler.ProcessRequest(HttpContext context) +103
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +317
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +65

I think the error is on the Atlas.js, but I can't figure it out.

Paulo Alves.


hello.

well, it looks like a permissions problem..are you running in medium trust?


Luis Abreu:

hello.

well, it looks like a permissions problem..are you running in medium trust?

I try even put in low trust, but the error is the same.

In my web.config I have the typical settings for Atlas:

<

sectionname="webServices"type="Microsoft.Web.Configuration.WebServicesSection"requirePermission="false"/>

<

sectionname="authenticationService"type="Microsoft.Web.Configuration.AuthenticationServiceSection"requirePermission="false"/>

<

sectionname="profileService"type="Microsoft.Web.Configuration.ProfileServiceSection"requirePermission="false"/>

<

httpHandlers>

<

removeverb="*"path="*.asmx"/>

<

addverb="*"path="*.asmx"type="Microsoft.Web.Services.ScriptHandlerFactory"validate="false"/>

<

locationpath="ScriptServices">

<

system.web>

<

authorization>

<

allowusers="*" />

</

authorization>

</

system.web>

</

location>

Thank you..

Paulo Alves.


Hello again!

I follow All the options addressed by Meisinger and Luis Abreu and with the change in the loaction of Javacript, I put it in the Head of the document, and using the Javascript Function:

timerRss1 = setTimeout("parser()", 1000);

Now it works without problems.

Thank you very mutch Meisinger and Luis Abreu for your tips.

Regards,

Paulo Alves.


hello again...

are you saying that putting the script block in the header solves the problem?


I thought the position of the script has influence, but I put it back in the body and still working. The change that solve me part of the problem was in the SCRIPTMANAGER:

<atlas:ServiceReferencePath="RSS.asmx"/>

When in the last version I put "Rss.asmx/js", like in examples of Atlas Team.

I make this change several times but did't work. I don't know why but now is working. A lot of people had experience some problems with atlas in some specific script blocks, maybe this has the same problem and by magic disappeared.

Regards,

Paulo Alves.


hello again.

ah, i've missed it...

well, you put the /js if you add the file by hand. for example, you could do this:

<script type="text/javascript" src="http://pics.10026.com/?src=rss.asmx/js">
</script>

when you use the scriptmanager, you can't add the /js since it'll add it automatically...

Calling a web service from an update panel

I am running through the tutorial on calling a web service from an update panel. I have a web site project and a separate web service project that contains the service that I'm trying to call. When I click the button that should make the call to the web service I get a javascript error that my web service is not defined. I am thinking that there is something wrong with the proxy that is getting created. So, I set the inlinescript property to true to see the .js that is getting generated. However, when I do this I get an error that : "The virtual path maps to another application which is not allowed". Does my web service file need to actually be in the same project as my website? This doesn't seem to make much sense because I have multiple web sites that call the same web service. What am I doing wrong here?

Thanks in advance

Hi Igouch,

Take a look at this:

http://ajax.asp.net/docs/mref/P_System_Web_UI_ServiceReference_Path.aspx

when you want to refer to a webservice that you have not in the same solution as your webproject you could use a bridge file to make it possible. otherwise if you want to complete the tutorial build the webservice in the same solution as the webproject. then you are able to set a direct reference to your webservice.

Hope it helps.


Right now I do have the web service in the same solution - but not the same project. Does the web service have to be in the same project as the web application? I am not familiar with doing this as we have always had a separate project for every web service that we've developed. Even though they are in the same solution I still am getting the message that the virtual path maps to a different application which is not allowed.

calling a web service from a secure site

I have hooked into a web service from our site and it has worked fine throughout development. Now that we've pushed the site live, the page that calls the service is a secure page and I get a javascript error on a line 3210. I'm assuming it's in the Atlas.js file (since I'm using Atlas to call the web service). That line says

_requestor.open('POST', _effectiveUrl,true);

I'm not sure what to do to fix this or if it's possible to fix it since I'm calling it from a secure page. Has anyone run into anything like this before and if so, how do you get around it? Or is it impossible to call an unsecure web service from a secure page? Thanks.

The browser generally limits calls from secure to unsecure pages. Is there any way you can put the web service on the same secure site?

thanks,
David


I'm having almost the same problem... the only difference is that the page is not a secure page...


Well, the service the page is calling is located on the same secure domain as the secure page. And in the atlas:ServiceReference Path, I specify the full secure url. It is in this service on the secure site that it calls the unsecure service. So, I would think that the browser wouldn't really know anything about the unsecure service since it's only calling a secure service. Unfortunately the unsecure service is not mine and I have no way to secure it. Is there any other type of work around for this? Thanks.

So if I understand correctly:

Your page in on the secure server. e.g.https://www.srv.com/app/page.aspx
Yes, you've got it. That's exactly how it's set up. The secure page calls a web service through Atlas on the same secure server. That service has a web reference set up to a non secure service. That's what I was afraid of, but I'm not sure then why it works if I go to the page as an unsecure url.

But where is the failure point? I assume that the call from Javascript to the secure server is correctly happening, and that it is the second call to the non-secure service that is failing?

If so, I would think this would happen without Atlas in the picture. e.g. if you make the same non-secure call from your page's Page_Load() method, does it fail in the same way?


Unfortunately because this is not on a my local box, I can't do any real step through debugging, but according to the error message, it looks like it's occurring in the atlas javascript call to the 1st (secure) service in atlas.js, line 3210, _requestor.open('POST', _effectiveUrl, true);.
I just tried something and found something interesting. I modified the atlas.js file and put an alert right before the line that's erroring with the url of the service it's trying to call. Even though I setup the serverreference path ashttps://secure..., when it alerts, it's coming back ashttp://secure... When I view source, the reference is still there as https, so I'm not sure why atlas is treating it as http. Maybe I'll have to just redo this in traditional ajax and forgo the Atlas handling.

Calling a WCF secure service

I know Atlas has some extensions to call WCF services but I am wondering is there any way to call a service using WS-Security instead of transport security (Https) ?.

Thanks

Pablo.

Hi Pablo,

Atlas is targeted on the "reach" end of the spectrum, which means it's pitched at technologies that are already widely deployed today. This necessarily means it can't take advantage of some of the richer protocol work like WS-Security because it's new and not everyone understands how to speak that stuff yet. I think of that as the "reach/rich tradeoff". The unfortunate reality is that you can't optimize for both at the same time.

However, history has shown that technologies that were once squarely in the 'rich' end of the spectrum have a tendency to become ubiquitous over time (a great example of this is DHTML, which has been around for years but has only recently become interesting).

Interesting times ahead :)
-steve
Thanks a lot Steve!!!. I just want to be sure about that.

Calling a simple Web Service from an ASPX page

Hi

I created a new Atlas web project, added a new web service and web page using the the code from the Simple.aspx and SimpleService.asmx.

Given I have identical code in the page and ws, I end up with 'Quickstart' is undefined error, on the following line of javascript:

requestSimpleService = Quickstart.Samples.SimpleService.EchoString(
document.getElementById('inputName').value, //params
OnComplete, //Complete event
OnTimeout //Timeout event
);

Any ideas?

It turns out in VS2005, when a new web service is created a code-behind is also created and placed into the App_Code directory. The problem I was getting was becuase the namespace reference was not the same as in the asmx.

Problem solved.


Great! Note that this behavior is optional, so if you prefer you can get the code inline in the asmx file (it's a checkbox on the add dialog).

David

Calling a Page Method Instead of a Web service method with javascript?

Hi All,

I am just wondering if it is possible to call a page method or a static method (non webservice) with javascript and have it return the results to the calling javascript funciton just like how it is done with a webservice call? Personally I prefer not to be producing asmx's for things that may only be used on a single page.

If so ... how might I accomplish this?

If Not.... Why not?

hehe

Thanks

Hi miskiw

Yes you can do that, you can find details here

http://ajax.asp.net/docs/tutorials/useWebServiceProxy.aspx at the bottom of the page titled "To call a static page method".

It is worth noting that there is a bug with this in the current release where you can only call methods that are inline. You cannot currently make async calls to methods that are in code behind.

HTH

Andy.


http://ajax.asp.net/docs/tutorials/useWebServiceProxy.aspx

can't open.

can you give a sample?THX


The new address is:http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx
In the bottom of the page, you have the section Exposing Web Services from an ASP.NET Web Page.

Basically, what you need to do is to create a static method and apply the [WebMethod] attribute to it.

[WebMethod]public static string EchoString(string name) {return"Called by " + name +".";}
HTH,
Maíra

Monday, March 26, 2012

Callback Scope on the client

I've started to play around w/ some of the basic Atlas features, mainly calling a web service from the client. One thing I noticed is that scope is lost during the asynchronous call to the server. If my javascript caller & callback method are part of an class, I've no way of telling Atlas to invoke the callback method w/ a specific object's scope.

Is this possible to do?

Cheers,
BobbyYou have a userContext parameter which you can pass as part of yourasynchronous call, that is what you can use to get back to the contextof your call, i.e. you can pass the object who's scope you want back aspart of the call...

Hope that helps,
-Hao
As I understood it, the userContext serves as a holder for contextual data that can be used inside the handler as an object - scope is still lost. Consider the following js class example:

TestClass = function(prop1)
{
this.propertyOne = prop1;

this.test = function()
{
MyCallbackServiceClass.Test({onMethodComplete: this.testCallback, userContext: this});
}

this.testCallback = function(result, user)
{
alert(this.propertyOne);
}
};

var t = new TestClass("This should persist before and after callback");
t.test();

When propertyOne is alerted in the testCallback method, it will be undefined because the scope is not preserved. I don't want the object as a parameter - I want to be operating within that object.
Mike Harder from the ASP.NET team, being the top-notch guy he is, answered this question for me. The scope is maintained by using a delegate.

CSharper.Net.CallbackService.Test({ onMethodComplete: Function.createDelegate(this, this.testCallback), userContext: this });

Callback after UpdatePanel

Is there a way to use a callback function in JavaScript after UpdatePanel complete

just like you can do when using a web service or PageMethods?

As so far, you?can?not?use?a?callback?after?asp:Update?is?updated?completely.Maybe?this?could?be?implemented?in?the?near?future.But?
you?can?define?a?LoadCompleted?event?in?a?custom?UpdatePanel?and?then?call?a?callback?after?it?updated?completely.?
If you would like to use callback,web service or PageMethods is better selection.
Wish this could give you some ideas.
yes but the only problem is that in web service or PageMethods (static) you don't have access to the controls on the page.

I found a solution to my problem.

and it is very simple also:

<script type="text/javascript" language="javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(PageLoadedEventHandler);
function PageLoadedEventHandler() {
// custom script
}
</script>

call web services using bridging (ajax beta 2)

I have several web service methods(implemented in .net 1.1) to call, in a different domain. The response I get when callin any methods from this web service is the page I see at the URL where .asmx is located. The .asbx is:

<bridge namespace="Support" className="OLOS" ><proxy type="Microsoft.Web.Preview.Services.BridgeRestProxy" serviceUrl="http://suppsite/SuppServices/OLOS.asmx" /><method name="getGeodisInfo" ><input><parameter name="OrderInformation" /><parameter name="BUID" /></input></method><method name="getExpeditorsInfo" ><input><parameter name="OrderInformation"/><parameter name="BUID" /></input></method></bridge>

And the .aspx file:

.............. <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="~/OLOS.asbx" /> </Services> </asp:ScriptManager>..............Support.OLOS.getGeodisInfo({ 'OrderInformation' : txtSearchText.value, 'BUID' : ' ' }, OnSucessgetGeodisInfo, OnError, "OLOS Search");.............. function OnSucessgetGeodisInfo(result) { if (result != null) { var resultText = result; document.getElementById('res1').innerHTML = resultText; } }
 
In the innerHTML of the DIV where I show results I get the content from the page located athttp://suppsite/SuppServices/OLOS.asmx
I do not see the actual call to the web method being done. Fiddler shows a call tohttp://suppsite/CareServiceCall/OLOS.asbx/js/getGeodisInfo but the response... does not contain what the method should return...
Any ideas?
Thanks

So I'm guessing your service url for the Asmx endpoint should behttp://suppsite/SuppServices/OLOS.asmx/<method>. What you'll need to do, is implement a TransformRequest in your Bridge codebehind, and as part of this, you need to set the ServiceUrl of the BridgeRequestl on the BridgeContext to the correct serviceUrl for your method. Since this is asmx, I imagine what you want to do is something like:

public override void TransformRequest() {
BridgeRequest.ServiceUrl = BridgeRequest.ServiceUrl + "/" + BridgeRequest.Method;
base.TransformRequest();
}

Hope that helps,
-Hao


Thanks for the response. Indeed that woulddefinitely help, at least a little bit later in the development phase.

What I am actually trying to do here is: I want to have all the methods for this web service(http://suppsite/SuppServices/OLOS.asmx/) defined in the same .asbx.

I know that changing serviceUrl tohttp://suppsite/SuppServices/OLOS.asmx/getGeodisInfo does the job, but then the rest of the methods defined in the .asbx are not callable. Using the url suffixed with the method name, works only if the web service has GET support, otherwise is not working for me. I also need to get this working when the web service works with POST only. I currently do not need transforms for method returns... at least not for all of them.

Is there a way to define in the same .asbx multiple methods and use them from javascript(except the way provided in the above sample)?


What I posted below dynamically changes the serviceUrl for each bridge request to be the correct one based on the method being called, which indeed it only works for GET, but if you want to support POST for asmx, you will need to build your own Proxy type for the bridge to make POST requests in the format ASMX expects, as the RestProxy only supports GET requests.

Hope that helps,
-Hao


Thanks Hao, everything is crystal clear now.

call web service using ASP.NET AJAX with javascript without callback function

Hello,

I'm trying to create a custom validator with a ValidatorCalloutExtender all in an Update Panel. As everyone knows the callouts do not currently display automatically after a server post-back and will only work for custom validators which utilize client-side validation.

When i call the javascript function from validator callout extender i must return the args.IsValid method before the function ends. If i use a callback function and try to return the args.IsValid from there the validator can't react because the IsValid method is set to late.

In conclusion, with AjaxPro framework this example works

 function descriptionRequiredValidate(source, args){
var ajaxResult = FileAdmin.AjaxMethods.IsDescriptionRequired(...);
var descriptionText = document.getElementById("tbFileDescription");
var descriptionRequired = ajaxResult.value;
if(descriptionText.value =="" && descriptionRequired){
args.IsValid =false;
}
else{
args.IsValid =true;
}
}
As you can see no callback function is required but when i try to use the ASP.NET AJAX with a web service i can't read ajaxResult. Do i make a mystake somewhere or this tipe of response(without callback) only works with ajaxpro 

Your simplest path is to move your final declaration of validity to the OnSuccess handler of the service call.

Call web service in Javascript

I used to use Atlas for calling web service in Javascirpt and everything works fine. After I upgrade to Ajax beta1 it stopped working. The error message is the web service class is undefined. I have updated web.config file manually. I also tested this by creating a new ajax toolkit web site. The following is the code. It give me the same error? Anyone can help? I also get a error message for one page I had never met before with Atlas. The error message is error:Sys.ArgumentException: Value must not be null for controls and Behaviors. parameter name:element.

Thanks.

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="Microsoft.Web.Configuration.ScriptingSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="webServices" type="Microsoft.Web.Configuration.ScriptingWebServicesSectionGroup, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="Microsoft.Web.Configuration.ScriptingJsonSerializationSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
<section name="profileService" type="Microsoft.Web.Configuration.ScriptingProfileServiceSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
<section name="authenticationService" type="Microsoft.Web.Configuration.ScriptingAuthenticationServiceSection, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
<tagMapping>
<add tagType="System.Web.UI.WebControls.CompareValidator" mappedTagType="Microsoft.Web.UI.Compatibility.CompareValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.CustomValidator" mappedTagType="Microsoft.Web.UI.Compatibility.CustomValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RangeValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RangeValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RegularExpressionValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.RequiredFieldValidator" mappedTagType="Microsoft.Web.UI.Compatibility.RequiredFieldValidator, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add tagType="System.Web.UI.WebControls.ValidationSummary" mappedTagType="Microsoft.Web.UI.Compatibility.ValidationSummary, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</tagMapping>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpHandlers>
<httpModules>
<add name="WebResourceCompression" type="Microsoft.Web.Handlers.WebResourceCompressionModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptModule" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>
<microsoft.web>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in Atlas applications, you need to add each property name to the setProperties and
getProperties attributes. -->
<!--
<profileService enabled="true"
setProperties="propertyname1,propertyname2"
getProperties="propertyname1,propertyname2" />
-->
</webServices>
</scripting>
</microsoft.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
</configuration>
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {

public WebService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

}

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services >
<asp:ServiceReference Path="~/WebService.asmx" />
</Services>
</asp:ScriptManager>
<div>
<script type="text/javascript">
function GetString()
{
strResult = WebService.HelloWord(alert(),alert());
alert(strResult);
}
</script>
<input type="button" id="Button1" onclick="GetString();" value="Click" />
</div>
</form>
</body>
</html>

Hi there, I think you forgot to append [Microsoft.Web.Script.Services.ScriptService] attribute in your webservice class. For example of simple webservice call, see myblog post orajax.asp.net docs.


Got it. Thanks for your advice. It is not mentioned in the migration manual. I also find you can not use AJAX controls on hidden field, at least it is true for AutoComplete. This caused the problem I mentioned in the first post. Hope this will help someone.

Call web service by Javascript in Logon.aspx

I used FormsAuthentication in my ajax-enabled website. Now I wanna call web service (in website) on client-side in Logon.aspx. But I always got an error that is like:

"WebService1" is undifined. (WebService1 is class name in the webservice)

I guess that's because ScriptManager will initialize webservice only after FormsAuthentication. Is this true? I can call webservice client-side in another aspx page.

If no any way for this, I have to give up FormsAuthentication.

Could you show us your code / markup?

You need to authorize anonymous users to access the web service. This can be done in many ways. The easiest way is to add an entry to the web.config file:

<location path="WebService1.asmx">
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>


Thank you, Rama. It works.

Call Web Service : can not return dataset

Hi,

I got an error : "A circular reference was detected while serializing an object of type 'System.Globalization.Cultureinfo' when returning a dataset variable. It didn't happen when returning string.

It also run smoothly when using PageMethods of Atlas.

What's wrong with the code :

<Microsoft.Web.Script.Services.ScriptService()> _Public Class EmpServiceInherits System.Web.Services.WebServiceDim cnHimalayaAs New SqlConnection( _ ConfigurationManager.ConnectionStrings("HimalayaConnectionString").ConnectionString) <WebMethod()> _Public Function GetData(ByVal SearchCategoryAs String,ByVal NIKAs String)As Data.DataSetDim strSQLAs String Select Case SearchCategoryCase"Experience" strSQL = _"SELECT JobTitle,Company,Period,JobDesc DeptName FROM Ht_HRD_Experience " & _"WHERE NIK ='" & NIK & "'" Case "Training" strSQL = _ "SELECT Training,Category,Year,Host,Location FROM Ht_HRD_Training" & _ "WHERE NIK ='" & NIK & "'"Case"Education" strSQL = _"SELECT Education,School,Subject,YearGraduate FROM Ht_HRD_EmpEducation " & _ "WHERE NIK ='" & NIK & "'"End Select Dim sqlDaAs New SqlDataAdapter(strSQL, cnHimalaya)Dim dsDataAs New Data.DataSetIf cnHimalaya.State = Data.ConnectionState.ClosedThen cnHimalaya.Open()End If Try sqlDa.Fill(dsData)Return dsDataCatch exAs SqlExceptionThrow (New ApplicationException(ex.Message))Finally cnHimalaya.Close() dsData.Dispose()End Try End Function

thanks.

The problem is the DataSet is not natively supported by the JavaScriptSerializer.
In order to return a DataSet, you need to implement and register a custom converter for the DataSet in the config file.
There is a DataTable converter that comes with the ASP.NET 2.0 AJAX Futures November CTP that you can try to use.

HTH,

Maíra


Thanks.

Do you have article that expalin more detail with example how to do that?

Rgds


Instead of the dataset-- why don't you just return Xml?

That's good idea. I'll use it for the next project because there is a lot of code i have to change for the current project.

thanks anyway.


Instead of the dataset-- why don't you just return Xml?

Eh because using XML is pretty much a pain to use in JavaScript? <s> Wno wants to parse XML on the client side when you could instead get an object back instead?

As to the DataTable converter it's broken in Beta 2 - it's still in Beta 2 but it's returning a bogus object which appears to be an internal object. It is possible to use the converter and grab the JSON it generates but this will likely change in the future so it's probably not a good idea to use.

Here's an example (Client Code):

 function GetCustomerTable_Callback(Result) { var List = ListControl.get_element();// retrieve raw DOM element // *** This is a HACK workaround AJAX Beta 1 until Microsoft brings back a real // *** DataTable Converter currently it contains a string property that has be eval'd // *** String has trailing ( that must be trimmed off var Text= Result.dataArray.substring(0,Result.dataArray.length -1); var Table = eval( Text);// *** Clear the list firstfor (x=List.options.length-1; x > -1; x--) { List.remove(0); }for (x=0; x < Table.length; x++ ) { var Row = Table[x];// Mozilla needs to assign var option = document.createElement("option"); option.text = Row.CompanyName; option.value = Row.CustomerId;if ( window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) List.add(option);else List.add(option,null); } }
 

On the server (WebService or PageMethod):

 [WebMethod]public DataTable GetCustomerTable() { busCustomer Customer =new busCustomer();if (Customer.GetCustomerList() < 0)return null; DataTable dt = Customer.DataSet.Tables["TCustomerList"];return dt; }

You also need to register the DataTableConverter:

<microsoft.web><scripting><webServices><!-- Uncomment this line to customize maxJsonLength and add a custom converter --><jsonSerialization maxJsonLength="50000"><converters><add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter"/></converters></jsonSerialization></webServices></scripting></microsoft.web>
 
+++ Rick -- 


I just downloaded AJAX v1.0 and now I get the circular reference error. I had the following code but I don't know what I have to change it to for my code to work properly.

<jsonSerialization maxJsonLength="50000"><converters><add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter"/></converters></jsonSerialization>

Anyone have any ideas? Thanks.


Sorry, this does work. I forgot to download the January Futures CTP.

You usually get this error when you try to serialize a DataTable that has no custom converter registered for it.

The Ajax v1.0 does not contain the converters for the DataTable, they are part of the ASP.NET AJAX Futures January CTP. You need to install this and add a reference to in in your project.

Have you done this?

Maíra


Hi folks,

I'm getting the same problem and am "stuck", so I appreciate some help !

I installed the ASP.NET AJAX Futures January CTP msi file.

I added a reference to my \BIN

C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Futures January CTP\v1.0.61025\Microsoft.Web.Preview.dll

I put this in the web.config:

<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000">
<converters>
<add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter"/>
</converters>
</jsonSerialization>
</webServices>

But still no go...

Do I have to MERGE the web_CTP.config with my standard AJAX 1.0 web.config or replace it entirely ?

It seems fairly complex to do so. Is their a pre-existing AJAX 1.0 / Jan CTP combined web.config available ?

Thanks, LA Guy


Hi again,

I missed these settings but still no go.

<jsonSerialization maxJsonLength="50000">
<converters>
<add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview"/>
<add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview"/>
<add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview"/>
</converters>
</jsonSerialization>

Thanks, LA Guy


I'm getting the same problem and am "stuck", thk


Guys I'm getting it working fine with the January CTP with the

<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<jsonSerialization>
<!--<jsonSerialization maxJsonLength="500">-->
<converters>
<add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</converters>
</jsonSerialization>

Config setting and the reference added to the Preview dll.

Can we assume these implementations would be included in the future MS Ajax releases bcoz I'm going to use these JSON converters for a real product.


I am running the latest AJAX 1.0 product set. When I apply the changes as mentiond above, I no longer am able to access my webmethod. I get a javascript error that states that method is undefined? when I comment the section above, I get circular reference encountred (since I am trying to return a datatable)

What am I doing wrong?

Call remotely hosted web service from client-side?

All of the examples I have seen call the *.asmx file using a relative path but I need to reference a URL such ashttp://www.domain.com/webservice.asmx to call a remote web service. In the Atlas days I believe this was done using a bridge (*.asbx) but I can't seem to find any recent information regarding this method. Does it still exist?

Anyone know how to accomplish this?

Thanks,
Janea

Hi,

my buddy Garbin (Allesandro Gallo) wrote an interesting article about this recently:Mash-it Up with ASP.NET AJAX: Using a proxy to access remote APIs.

Grz, Kris.


Wow!Yes What an excellent article!! I actually ran across it when I was initially searching for an answer but I thought there might be an easier way, however it makes a lot of sense why it is done the way he describes it. So, I'm going to try it out... create a local web service to be used as a proxy to connect to the URL containing the web service and call the remote procedures from there. Seems like a simple concept... I feel like I should've figured it out on my own. Well we'll see how it goes... Thanks a ton Kris!