Showing posts with label webservices. Show all posts
Showing posts with label webservices. Show all posts

Monday, March 26, 2012

Chaining Multiple Webservices

OK, with the support of the very helpful moderators, I've successfully built several bridges to external web services, and I'm getting the results transformed into json for use on my page. So far so good. Now I've reached the point where the async nature of all of this is throwing up an obstacle. Here's the basics of what I'm trying to do:

    Call WebService1 which gives me a list of addresses.Call WebService2 for each address that returns the coordinates for the address.Pass an array of these coordinates to a mapping service to plot on a map.

So, I'm successfully calling WebService1, getting the results, and then looping through the results and passing each one to WebService2. The problem is that I don't want to do #3 until the loop is done, and I have all of my coordinates in my array. But since it is all asynchronous, I'm not sure how to know when to kick off #3. First of all, is it possible to handle this in the javascript?

If that's not possible, then I considered the concept of "Chaining Multiple Bridge Requests". Since, the return from WebService1 is a list of addresses, but the input for WebService2 is a single address, I assume that I couldn't "declaratively" chain the requests. Is that correct?

Assuming that I can't do that, then, is my best bet to "programatically" chain multiple bridge requests, where all of my looping through the WebService1 results is done in the code-behind of the WebService1 bridge?

Thanks again for the help.

Sure you can do this either thru Javascript or programatically chaining the bridges as well. Basically if you want to do this in Javascript, you simply need to use a special OnComplete handler for the second webservice which kicks off Webrequest #3. Your other option is just to do all 3 of these requests in one bridge, and chain them up on the server in the code-behind as you mentioned.

Something like:

OnCompleteWebService2Chain(results) {

// <package up results for webrequest 3>
MappingService.Plot(transformedResults, OnComplete3, ...

}

Or in your codebehind:

object results1 = BridgeHandler.Invoke(<webservice1.asbx>, new BridgeRequest(method1, args);
IDictionary args2 = TransformResults1IntoArgs2(results1)
object results2 = BridgeHandler.Invoke(<webservices2.asbx>, new BridgeRequest(method2, args2);
...etc

Hope that helps,
-Hao


Well, that didn't clear it up too much, but a friend of mine gave me some guidance. Here's basically how I handled it:

var totalResults = 0;var coordinates =new Array();function OnWebService1Complete(searchResults){ totalResults = searchResults.length;for (i=0; i < totalResults ; i++) {//Call WebService2 Yahoo.GeoCode.GetCoordinates({location : searchResults[i].Address}, OnWebService2Complete, OnTimeout, OnError); } }function OnWebService2Complete(results){//simplified for example coordinates.push(results);if (coordinates.length == totalResults) {//All coordinate results must be in the array //So it's safe to initialize the map map.SetBestMapView(); }}

Saturday, March 24, 2012

CascadingDropDown without WebServices

one of the new thing in the new release is that:

"CascadingDropDown can now call PageMethod as well as web services (Just leave the ServicePath property blank)"

is it possible to add an example so I can start, please...

I have all in a Class, and it work fine but I wonder if I can do this without postback's

http://portal.filterqueen.dk/

the country dd is populate from a Class function called
getAllCountries( ByVal dd as DropDownList )

the Offices are populate almost the same
getAllOfficesFromCountry( ByVal dd as DropDownList, ByVal country as String )

How can I ask for this functions and send it the parameters in the new CascadingDropDown?

Hi Bruno,

The newest version of the Toolkit includes an example of doing this in the CascadingDropDown.aspx file of the sample website. You'll notice that there are three Cascading DropDowns on the page and the first calls a page method while the second two call a webservice.

Thanks,
Ted

Wednesday, March 21, 2012

CascadingDropDown Memoryleak, something with ParentControlID?

Hi, I'm currently using two cacadingdropdown extenders which retrieves data from webmethods (no webservices) embedded in aspx page. One is the parent of the other. And now each time I refresh the memory increases 800-1000K at the time. But the strange thing is that if i remove the parent child relationship (no extender has parentcontrolid defined) the memory leaks do not accur.

Am I doings something wrong, is something missing in webconfig?

12<!--34-->5<configuration>6<appSettings/>7<connectionStrings>8<add name="UtstyrConnectionString" connectionString="Data Source=WIN2003STDBASE;Initial Catalog=Utstyr;Integrated Security=True" providerName="System.Data.SqlClient"/>9</connectionStrings>10<system.web>11<pages enableEventValidation="false"></pages>1213<compilation debug="true">14<assemblies>15<add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>16<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>1718<authentication mode="Windows"/>19 <identity impersonate="true"/>20 <authorization>21 <allow users="*"/>22 </authorization>23<httpHandlers>24<remove verb="*" path="*.asmx"/>25<add verb="*" path="*.asmx" validate="false" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>26<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>27</httpHandlers>28<httpModules>29<add name="WebResourceCompression" type="Microsoft.Web.Handlers.WebResourceCompressionModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>30<add name="ScriptModule" type="Microsoft.Web.UI.ScriptModule, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>31</httpModules>32</system.web>33</configuration>

Cheers GauteO

PS both my dropdownboxes and cacadingdropdownextenders are in an updatepanel

Here is a simple sample of what I mean. If anybody could run this to determine if it is a internal problem.

1<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>2<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>3<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"4 Namespace="Microsoft.Web.UI" TagPrefix="asp" %>5<script runat="server">6 [System.Web.Services.WebMethod]7 [Microsoft.Web.Script.Services.ScriptMethod()]8 public static AjaxControlToolkit.CascadingDropDownNameValue[] Get(string knownCategoryValues, string category)9 {10 int count = 5;11 AjaxControlToolkit.CascadingDropDownNameValue[] cddnv = new AjaxControlToolkit.CascadingDropDownNameValue[count];12 for (int i = 0; i < count; i++)13 cddnv[i] = new AjaxControlToolkit.CascadingDropDownNameValue("Gaute" + i, i.ToString());14 return cddnv;15 }16 </script>17<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">18<html xmlns="http://www.w3.org/1999/xhtml" >19<head runat="server">20 <title>Untitled Page</title>21</head>22<body>23 <form id="form1" runat="server">24 <div>25 <asp:ScriptManager ID="ScriptManager1" runat="server">26 </asp:ScriptManager>27 <asp:DropDownList ID="DropDownList1" runat="server">28 </asp:DropDownList>29 <asp:DropDownList ID="DropDownList2" runat="server">30 </asp:DropDownList>31 <cc2:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="Valg" LoadingText="Laster" PromptText="Velg" ServiceMethod="Get" TargetControlID="DropDownList1">32 </cc2:CascadingDropDown>33 <cc2:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="Velger" LoadingText="Laster" PromptText="Velg" ServiceMethod="Get" TargetControlID="DropDownList2" ParentControlID="DropDownList1">34 </cc2:CascadingDropDown>35 </div>36 </form>37</body>38</html>

This code gives me a memory leak of 700-1000k each time the page posts back. And if I remove the ParentControlId from CacadingDropDown2 (line 33) the memomry leaks stops. Testet the samplewebsite in ajaxtoolkit (cacadingdropdown) and that didn't have the memoryleaks. I have tried to elumate(copy) the procedure in the site, but cant stop the leaks.

GauteO


*bump*

also tried with RC1 release, same problem..


What Browser are you testing with? Or is this problem occuring in all browsers?

The reason I ask, is that I found that several issues with the CascadingDropDowns disappeared when I moved to IE 7.0. For example, with IE 6.x I have found that having two different sets of CascadingDropDowns on the same page will break the functionality of the SelectedValue tags... Only the first set of CascadingDropDowns will get the correct initial value...


Currently I have only testet with ie6, I shall test on other browser when I get to work again (as I'm currently home). I usally test in opera, firefox, ie6 and ie7+(vista browser). But I am really cursious if anybody else get this memory leak when one of the cascadingdropdown extenderes has an parentcontrolid assign to it, and stops when none have an parentcontrolid. They provide/retrieves the same information in both instances, only diffrence that the cacadingdropdown with parentcontrolid has the "knownvalues" of its parent (and 700-1000k is pretty much for 5 values beeing sent, as in the sample in the second post). Maybe I must embed the information in XML (as they do in the sample site ajaxcontrolkit)?

Hmm, I have testet the scenario on opera and ie7+ and the memory leaks do not accur. I also testet the sitehttp://ajax.asp.net/ajaxtoolkit/CascadingDropDown/CascadingDropDown.aspx again, with ie6, and the memory leak problem accurs there too (was sure that I tested this before and didn't have the problem, it was beta2 not rc1 which I testet now). It seems that ie6 is the problem, I am running 2003 server on a virtual pc(vmware), but it does not have the latest updates (trying to install them, but windows update just stops). Maybe this problem only accurs on old versions of ie6 (IE that follows a clean install of 2003 server), if anybody could confirm this it would be of great help (use the cacadingdropdown example on the ajaxcontrolkit website). My current version of ie6 is:

GauteO


That this doesn't happen in other browsers (including IE7) suggests to me that it's probably not something the Toolkit is doing wrong. Please let us know what happens with an updated IE6.

CascadingDropDown incompatible with WebServices using GET?

I'm using a trio of cascadingdropdowns representing country/state/city throughout a web application I'm developing for a client. They've recently reduced their internet speed dramatically (from 7mbps to 728k) and suddenly I've had to become more concerned about bandwidth usage.

I'd like to switch my webservice to use GET so that client browsers can cache the results without re-requesting from the server, unfortunately when I try, my select boxes show the error: 12030 (occasionally 12031)

WebService Code:

1<Services.WebMethod(cacheduration:=60), Script.Services.ScriptMethod()> _2Public Function GetCountries(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As CascadingDropDownNameValue()3Dim cachedurationAs TimeSpan = TimeSpan.FromMinutes(1)4Dim maxageAs System.Reflection.FieldInfo = HttpContext.Current.Response.Cache.GetType().GetField("_maxAge", Reflection.BindingFlags.InstanceOr Reflection.BindingFlags.NonPublic)5 maxage.SetValue(HttpContext.Current.Response.Cache, cacheduration)6 Context.Response.Cache.SetCacheability(HttpCacheability.Public)7 Context.Response.Cache.SetExpires(Now.Add(cacheduration))8 Context.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate")9Dim cadapterAs New ltcodebehind.DSTablesTableAdapters.countryTableAdapter10Dim ctableAs New ltcodebehind.DSTables.countryDataTable11 cadapter.Fill(ctable)12Dim valuesAs New List(Of CascadingDropDownNameValue)13For iAs Integer = 0To ctable.Count - 114 values.Add(New CascadingDropDownNameValue(ctable(i).Title, ctable(i).ID))15Next1617 Return values.ToArray1819End Function

Client source code

1 <asp:ScriptManager runat="server" ID="acm1" >23 </asp:ScriptManager>4 <ajaxtoolkit:CascadingDropDown runat="server" ID="atlascascmgr" ServicePath="../Services/skService.asmx" SelectedValue="229" Category="country" ServiceMethod="GetCountries" TargetControlID="ddlcountry" />5 Country<br />6 <asp:DropDownList ID="ddlcountry" runat="server" />

Some notes

The only different on whether I receive an error 12030 is whether I have theusehttpget:=Truein the scriptmethod, so my cascadingdropdowns are configured properly for POST operations, I specifically need to know what I can change to get it to accept GET operations.

Usually its around this time that someone might offer up serverside caching, so I'm going to go ahead and answer that question now. 1) I appreciate the goodwill, I'm not being snarky, just trying to preemptively headd of the answer 2) I'm caching the webservice via the cacheduration:=60 up above, it just doesn't help because the server has power to spare, its the clients browsers that need the help.

Thanks everyone for their potential answers. :)

The third parameter to ASP.NET AJAX's Sys.Net.WebServiceProxy.invoke method is called "useGet" and tells it whether to use GET or POST for the web service call. The Toolkit's CascadingDropDownBehavior.js currently hard-codes this parameter to false (meaning "use POST"), so that's likely the source of the problem here. You should be able to change the value to true and rebuild for your client. If that works for you, pleaseopen a work item to ask that we expose this setting as a parameter to CascadingDropDown extender itself so that it will be easy to change for others who might want to do so. Thank you!

Very interesting, I'll do it when I have the time and if it works, open the work item like you describe.

Thanks!