Showing posts with label successfully. Show all posts
Showing posts with label successfully. 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(); }}

CascadingDropDownProperties not recognised in AJAX

Hi,

I've been using CascadingDropDowns quite successfully in Atlas but have now hit a problem moving to ASP.NET AJAX.


I get a message saying "Element 'CascadingDropDownProperties' is not a known element. This can occur if there is a compilation error in the web site."

When I compile, I get an error message saying "'AjaxControlToolkit.CascadingDropDown' does not have a public property named 'CascadingDropDownProperties'".

In my VB code, I import the AjaxControlToolkit but I get a message saying "Type 'CascadingDropDownProperies' is not defined" and "'GetTargetProperties' is not a member of 'AjaxControlToolkit.CascadingDropDown'".

It almost seems as though CDD properties have been dropped, but that can't be right - can it?

I guess I must be missing something fundamental. Any ideas? I have pasted by code below and highlighted the offending lines...

-- Search.aspx --
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" CodeFile="Search.aspx.vb" MasterPageFile="~/MasterPage.master" Inherits="Search" Title="TiberPass: Property Search Page" %
<%@dotnet.itags.org. Register
Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="AjaxCTK"
%
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<AjaxCTK:CascadingDropDown ID="cdd" runat="server" >
<AjaxCTK:CascadingDropDownProperties
Category="Province"
PromptText="-- Any Province --"
ParentControlID="ddlRegion"
ServiceMethod="GetProvincesForRegion"
ServicePath="ListcountService.asmx"
TargetControlID="ddlProvince" />
<AjaxCTK:CascadingDropDownProperties
Category="Town"
ParentControlID="ddlProvince"
PromptText="-- Any Town --"
ServiceMethod="GetTownsForProvince"
ServicePath="ListcountService.asmx"
TargetControlID="ddlTown" />
<AjaxCTK:CascadingDropDownProperties
TargetControlID="ddlRegion"
Category="Region"
ServicePath="ListcountService.asmx"
ServiceMethod="GetRegions"
PromptText="-- Any Region --" />
</AjaxCTK:CascadingDropDown>
....


-- Search.aspx.vb --
Imports AjaxControlToolkit

Partial Class Search
Inherits SmartSessionPage

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

' Retrieve Atlas Cascading Dropdown settings from session variables
Dim properties AsCascadingDropDownProperties

' Region
properties = cdd.GetTargetProperties(ddlRegion)
If properties IsNot Nothing Then
If RegionID <> Nothing Then
properties.SelectedValue = RegionID
End If
End If

' Province
properties = cdd.GetTargetProperties(ddlProvince)
If properties IsNot Nothing Then
If ProvinceID <> Nothing Then
properties.SelectedValue = ProvinceID
End If
End If

' Town
properties = cdd.GetTargetProperties(ddlTown)
If properties IsNot Nothing Then
If TownID <> Nothing Then
properties.SelectedValue = TownID
End If
End If

End Sub

End Class

-- MasterPage.Master --
<%@dotnet.itags.org. Master Language="VB" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Tiber Pass</title>
<link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=css/main.css"/>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
<asp:ScriptManager ID="ScriptManager1" runat="server" enablepartialrendering="true">
</asp:ScriptManager>
</div>
</form>
</body>
</html
-- Web.config --
<?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 tagPrefix="asp" namespace="Microsoft.Web.Preview.UI" assembly="Microsoft.Web.Preview"/>
<add tagPrefix="asp" namespace="Microsoft.Web.Preview.UI.Controls" assembly="Microsoft.Web.Preview"/>
</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="false">
<assemblies>
<add assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></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"/>
<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
</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 ASP.NET AJAX applications, you need to add each property name to the setProperties and
getProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="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"/>
<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
</handlers>
</system.webServer>
</configuration

Android:

Hi,

I've been using CascadingDropDowns quite successfully in Atlas but have now hit a problem moving to ASP.NET AJAX.


I get a message saying "Element 'CascadingDropDownProperties' is not a known element. This can occur if there is a compilation error in the web site."

When I compile, I get an error message saying "'AjaxControlToolkit.CascadingDropDown' does not have a public property named 'CascadingDropDownProperties'".

In my VB code, I import the AjaxControlToolkit but I get a message saying "Type 'CascadingDropDownProperies' is not defined" and "'GetTargetProperties' is not a member of 'AjaxControlToolkit.CascadingDropDown'".

It almost seems as though CDD properties have been dropped, but that can't be right - can it?

The properties have been moved for the new release of ASP.NET AJAX. There's more information in themigration guide for the toolkitand examples of how the new approach works in thesample page for the cascading dropdown control. I hope this helps!


Ah! That explains it. I thought I must have missed something pretty fundamental. Thanks for that.

I've been attempting to convert my code, but come across a problem when I try to use CascadingDropDownProperties and GetTargetProperties. I guess these don't exist any more but what do I use instead? Sorry if this seems basic, but I'm not very technical and am only using VB.NET reluctantly (I kind of hoped Atlas/Ajax would do it all for me, sigh). The examples are in C#.

I'm trying to set my drop down lists based on saved session variables. It was working OK in Atlas, but now I'm struggling. Any ideas? Here are the main parts of my code with the offending bits highlighted:

-- Search.aspx --
<AjaxCTK:CascadingDropDown
ID="cddProvince"
runat="server"
Category="Province"
PromptText="-- Any Province --"
ParentControlID="ddlRegion"
ServiceMethod="GetProvincesForRegion"
ServicePath="ListcountService.asmx"
TargetControlID="ddlProvince"
LoadingText="Loading Provinces..." />
<AjaxCTK:CascadingDropDown
ID="cddTown"
runat="server"
Category="Town"
ParentControlID="ddlProvince"
PromptText="-- Any Town --"
ServiceMethod="GetTownsForProvince"
ServicePath="ListcountService.asmx"
TargetControlID="ddlTown"
LoadingText="Loading Towns..." />
<AjaxCTK:CascadingDropDown
ID="cddRegion"
runat="server"
TargetControlID="ddlRegion"
Category="Region"
ServicePath="ListcountService.asmx"
ServiceMethod="GetRegions"
PromptText="-- Any Region --"
LoadingText="Loading Regions..." /
-- Search.aspx.vb --
Dim properties AsCascadingDropDownProperties

' Region
properties = cddRegion.GetTargetProperties(ddlRegion)
If properties IsNot Nothing Then
If RegionID <> Nothing Then
properties.SelectedValue = RegionID
properties = RegionID
End If
End If



Android:

Ah! That explains it. I thought I must have missed something pretty fundamental. Thanks for that.

I've been attempting to convert my code, but come across a problem when I try to use CascadingDropDownProperties and GetTargetProperties. I guess these don't exist any more but what do I use instead? Sorry if this seems basic, but I'm not very technical and am only using VB.NET reluctantly (I kind of hoped Atlas/Ajax would do it all for me, sigh). The examples are in C#.

I'm trying to set my drop down lists based on saved session variables. It was working OK in Atlas, but now I'm struggling. Any ideas? Here are the main parts of my code with the offending bits highlighted:


-- Search.aspx.vb --
Dim properties AsCascadingDropDownProperties

' Region
properties = cddRegion.GetTargetProperties(ddlRegion)
If properties IsNot Nothing Then
If RegionID <> Nothing Then
properties.SelectedValue = RegionID
properties = RegionID
End If
End If


I think they changed how you access the individual dropdownlists. You can now directly access them, so if you want to set the selectedValue of the ddlRegion control, do this:

cddRegion.SelectedValue = RegionID

I assume RegionID is stored somewhere in Session. It sounds like you're doing that.

One thing I would watch out for is the order you set the selectedValues for the cascading dropdowns. I haven't used the control yet, but I assume it might have problems if you don't assign a value to the parent dropdownlist, then the one under it, then the one under it, and so on.

Best of luck, let us know how it went!


That's great. It's much easier now.

You're right, I'm storing RegionID, etc. as session variables. The idea is that the drop downs will retain the user selections when they return to this page. I had it working fine before.

Now I have a new problem. For some reason the code I have written in my search page to populate the drop downs is not being executed. I have set up 3 drop downs with 3 associated CDDs. The dropdowns should call service methods like "GetRegions" and "GetProvincesForRegion", etc. within ListCountService.asmx, but it never gets that far. The drop downs come up with a Method Error 500. I've put a breakpoint in GetRegions, but it doesn't get activated. Maybe it's something in my header? Before, I had EnableEventValidation, EnableViewState and AutoEventWireup set to false. Now I just have AutoEventWireup set to true and don't mention the other two.

The code for Search.aspx hasn't changed since my last post and I haven't touched the code in ListCountService.asmx. Besides, no matter how good or bad the code is, it just isn't running!

I really appreciate your help on this.

Andrew


Check out Cranzy's post inthis thread andthis blog post by Shawn Burke. I hope this helps!

Fantastic! That's solved it and it's all working fine now. Thanks very much. I'm pretty sure I wouldn't have spotted that other post or blog entry without a nudge in the right direction.

Thanks again,

Andrew