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

Monday, March 26, 2012

PROBLEM - Timer Control calling Web Service?

Hi,

I have an issue, where I need to utiliize the AJAX Timer Control to continously poll an AJAX Web Service. Now I have successfully been calling the Web Service directly from Javascript, without any issue, however I need to perform some server-side actions.

Hence i need to use the Timer control to perform a onTick event call, which uses the same AJAX Web Service on the server side as follows:

iWebService ws = new iWebService();

string response = ws.iFunction("some data");

The problem here is i recieve the following error on every interval call from the Timer;

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500

If anyone can help here, then that would be great, otherwise a temporary solution for my problem is to get the Timer to call a client side function instead of the server side one, and then for me to make a traditional Javascript request to the Web Service. If anyone knows how to do this, I would be very greatful.

Thank you!

We'd need to see some code to figure out what's going on, but rather than using the server Timer control, you're probably better off downloading the Futures January CTP and using the Sys.Preview.Timer control in there.

Hi, Steve

<formid="mainform"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"><Services><asp:ServiceReferencePath="iWebService.asmx"/></Services></asp:ScriptManager><asp:Timerid="timToolBar"runat="server"OnTick="Refresher"Interval="5000"></asp:Timer><asp:UpdatePanelID="upToolBar"runat="server"UpdateMode="Conditional"><Triggers><asp:AsyncPostBackTriggerControlID="timToolBar"/></Triggers><ContentTemplate><uc2:ctrlToolBarID="ToolBar"runat="server"/></ContentTemplate></asp:UpdatePanel>
//CODE BEHIND FILE 

protected void Refresher(object sender, EventArgs e)

{

iMediaService ws =newiMediaService();

string response = ws.GetEvent(sessionid.Value, 2000);

//Some code here to update the Toolbar

}

It's pretty simple to be honest, the call to the WS basically returns some info I use to update the ToolBar. I need to call the WS continuosly, but information is only returned if the iWebService.RegisterClient is called first, before this, the call to GetEvent returns an empty string, which is correct. But after the RegisterClient has been called, i should get some data back from every call to the ws.GetEvent function.

Simple Call Logic

1. Register Client

2. Repeat call to GetEvent & Update ToolBar

The first call to GetEvent after the RegisterClient works fine and i recieve the correct data, but after that, when the Timer fires every interval, i get that error message. The ToolBar is a Web User Control, now simply I could just output the response string from GetEvent to a TextBox for testing, but like i said, the first call is fine, after that it just throws that error.

Also as i was debugging this, the debugger was not breaking on my breakpoint on the first line of the Refresher function, i think theres a problem after i write some info to the ToolBar.


The 500 suggests that something's breaking on the server. I would recommend grabbingNikhil's Web Development Helper and taking a look at the request and 500 response. It's quite likely the contents of the response will show you exactly what the problem is.

(As it is, I can't really guess what's going wrong.)

Saturday, March 24, 2012

Problem binding DataTable to ListView using "set_data(result)"

Hello,

I'm calling a web service which is providing a DataTable to my client ASP.NET AJAX javascript code. I'm then trying to bind that data table to a client listview control. The code runs without error message but no results are displayed, despite the datatable having positive content. The problem seems to arise because the "set_data" makes a call to "render" and in that method it checks the validity of "get_length", which the client DataTable does NOT support, so the code falls out to the "Empty Data" template. Basically it seems that ASP.NET AJAX is not expecting to see a DataTable at all, but something else. Can anyone help me with this please?

Here is my page code, the WebService.asmx simply returns a DataTable and "main()" simply wires up the button to kick the process off. the commented code will successfully display the data as an unordered list (simulating a listview):

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="ListViewUnorderedList.aspx.cs" Inherits="ListViewUnorderedList" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script>
function main()
{
document.getElementById("btnLoadVendors").onclick = getVendors;
}

function getVendors()
{
var onVendors = function(result)
{

// result is a dataset or data object
var ele = document.getElementById("output");
var ctl = ele.control;
ctl.set_data(result);

/* This would work and do the same job...
ele.innerHTML = "<ul>";
for (var i=0; i<result.rows.length; i++)
{
ele.innerHTML += "<li>" + result.rows[i].Name + "</li>";

}
ele.innerHTML += "</ul>";
*/
}
WebService.getVendors(onVendors);
}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewGlitz.js" />
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewDragDrop.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<script>
Sys.Application.get_events().addHandler("load", main);
</script>
<input id="btnLoadVendors" type="button" value="Load Vendors" />
<!-- Template for output -->
<div id="output">
Vendor list goes here.
<div style="display:none">
<div id="vendorsLayout">
<ul id="vendorsItemParent">
<li id="vendorsItem">
<span id="vendorsName">Vendor Name goes here</span>
</li>
</ul>
</div>
</div>
</div>
</form>



<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<listView itemTemplateParentElementId="vendorsItemParent" id="output">

<layoutTemplate>
<template layoutElement="vendorsLayout" />
</layoutTemplate>

<itemTemplate>
<template layoutElement="vendorsItem">
<label id="vendorsName">
<bindings>
<binding dataPath="Name" property="text" transform="ToString" />
</bindings>
</label>
</template>
</itemTemplate>

</listView>
</components>
</page>
</script>
</body>
</html>

bump

With hindsight, perhaps I've worded this problem all wrong.

Basically, the "set_data" method of a client control does not accept/understand an ASP.NET AJAX Client datatable object, as I was led to believe it did.

So what object structure do you pass to it?


Well, it looks as if the answer is to pass it the "rows" property of a datatable, this seems to work:

document.getElementById(

"output").control.set_data(result.rows);

Problem calling Web Service using the DynamicPopulate Extender - Web Service Call Fails: 5

Hi, I'm quite new to ASP.Net AJAX so please forgive my ignorance.

I have downloaded and installed the RC1 version and am following through some of the tutorial videos.

I am having a problem with the Dynamic Populate Extender example. I have created some asp controls with onclick events calling a javascript function. From there I am attempting to use a dynamic populate extender control to call a web service - it's a function declared on that ASPX page as the tutorial explains in necessary and decorated with the System.Web.Services.WebMEthod AND System.Web.Script.Services.ScriptMethod attributes.

Everything works as expected until I attempt to pass a parameter to the web services - in fact until I declare the web service function with a parameter. Once I do this, all that is returned to (or at least all that displays in) the control linked to the DynamicPopulateExtender is "Web Service Call Failed: 500".

Can anyone possibly put me on the right track here? (or would I need to post some code examples?)

Thanks in Advance.

Stu.

the tutorial is in beta version.

i will post my code for you

ASPX page

<%@. Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="DynamicPopulateDemo._Default" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

</head>
<body>

<form id="form1" runat="server">
<script type="text/javascript">

function updateDateKey(value) {

var behavior = $find('dpe');

if (behavior) {
behavior.populate(value);
}

}

Sys.Application.add_load(function(){updateDateKey('G');});
</script>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:DynamicPopulateExtender ID="dpe" runat="server" ClearContentsDuringUpdate="true"
PopulateTriggerControlID="Label1" TargetControlID="pan" ServiceMethod="GetHtml">
</cc1:DynamicPopulateExtender>

<p>
<asp:Label ID="Label1" runat="server" Text="Label" CssClass="subheading">Time at the server:</asp:Label>
</p>
Choose a date/time format:<p>
<label for="r0"><input type="radio" name="rbFormat" id="Radio1" value='G' onclick="updateDateKey(this.value);" checked="checked" />Normal</label><br />
<label for="r1"><input type="radio" name="rbFormat" id="Radio2" value='d' onclick="updateDateKey(this.value);" />Short Date</label><br />
<label for="r2"><input type="radio" name="rbFormat" id="Radio3" value='D' onclick="updateDateKey(this.value);" />Long Date</label><br />
<label for="r3"><input type="radio" name="rbFormat" id="Radio4" value='U' onclick="updateDateKey(this.value);" />UTC Date/Time</label><br />
</p>
<br />
<p>

This time is dynamically formatted and<br /> returned as HTML from the server:

<asp:Panel ID="pan" runat="server" BorderColor="#404040" BorderStyle="Solid" BorderWidth="1px" Height="15px" HorizontalAlign="Center" Width="380px">
</asp:Panel>
</p>

</form>


</body>

</html>

ASPX.CS

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace DynamicPopulateDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[System.Web.Script.Services.ScriptMethod]
[System.Web.Services.WebMethod()]
public static string GetHtml(string contextKey)
{
System.Threading.Thread.Sleep(250);
string value = string.Empty;

if (contextKey == "U")
{
value = DateTime.UtcNow.ToString();
}
else
{
value = String.Format("{0:" + contextKey + "}", DateTime.Now);
}
return String.Format("<span style='font-family:courier new;font-weight:bold;'>{0}</span>", value);


}
}
}


Thankyou very much for posting this code.

I have worked through the differences between your version of the tutorial and the code I was trying to get running. It all boiled down to the name of the parameter on the web service method. I don't understand this yet but if I call the parameter on my web service method, "contextKey" it works, if I call it anything else, it fails.

Is anyone able to shed some light on this for me?


In the documentation it states that the paramater must be astring namedcontextKey

[WebMethod]string DynamicPopulateMethod(string contextKey) { ... }

Note you can replace "DynamicPopulateMethod" with a naming of your choice, but thereturn type and parameter name and type must exactly match, including case.

Problem getting AutoComplete Extender to work

Hi I just want to get the autocomplete extender to work with a text box and I'm having trouble getting it to work. It seems like the service isnt being called or that the control isnt working. Compiles fine and no errors in IE when its opened

Heres the code.

AJAXServices.asmx

<%@dotnet.itags.org. WebService Language="VB" CodeBehind="~/App_Code/AjaxServices.vb" Class="AjaxServices" %>

AJAXServices.vb

Imports DataAccess
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GetModelList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim strSQL As String
Dim titleArList As New List(Of String)
Dim dtModels As DataTable

strSQL = "SELECT DISTINCT Alias FROM LaptopDescTier WHERE Alias LIKE @dotnet.itags.org.Model"
strSQL = strSQL.Replace("@dotnet.itags.org.Model", FormatSQLInfo(prefixText & "%"))
dtModels = ReturnTable(strSQL)

For Each drModel As DataRow In dtModels.Rows
titleArList.Add(drModel("Alias").ToString)
Next

Return titleArList.ToArray()

End Function

End Class

UpdateLaptopModels.aspx

<%@dotnet.itags.org. Page AutoEventWireup="false" CodeFile="UpdateLaptopModels.aspx.vb" Inherits="UpdateLaptopModels"
Language="VB" MaintainScrollPositionOnPostback="true" MasterPageFile="~/Admin.master"
Title=":: Laptop Management System ~ Administration ::" %
<asp:Content ID="Content1" runat="Server" ContentPlaceHolderID="cphAdmin">
<asp:ScriptManager ID="ScriptManager" runat="server">
</asp:ScriptManager>
<div class="Container">
<h2>
Update Laptops Models</h2>
<div class="StandardBreakSpace">
</div>
<asp:TextBox ID="txtAlias" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="aceAlias" runat="server" CompletionInterval="1000"
CompletionSetCount="12" EnableCaching="true" MinimumPrefixLength="1" ServiceMethod="GetModelList" Enabled="true"
ServicePath="Services/AjaxServices.asmx" TargetControlID="txtAlias">
</ajaxToolkit:AutoCompleteExtender>
</div>
</asp:Content>

Web.config

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>

</appSettings>
<connectionStrings>

</connectionStrings>
<system.web>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
</pages>
<identity impersonate="true"/>
<authentication mode="Windows"/>
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm">
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
</customErrors>
<!--
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="System.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="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<profile>
<properties>
<add name="SearchTerms" type="System.Collections.Specialized.StringCollection" serializeAs="Xml"/>
</properties>
</profile>
</system.web>
<system.web.extensions>
<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 readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
</configuration


Once I get this working I want to use the text box and extender in a itemtemplate in a gridview. Will that work?

Thanks for looking into this and all suggestions are welcome!

Dude, found it!!!

change this...


<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class

TO

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class


I'll give this a try at work tomorrow. I just gave up. If this works, you are truly the man!Wink



If not, you can try this:

http://forums.asp.net/thread/1563579.aspx

I had trouble getting autocomplete in vb to work, and listed a few things I noticed there.

(Using in-page methods, no .asmx)


Jared,

Unfortunately even this doesnt get it to fire. I wonder if you could put together a quick sample that fires in VB to use as a template.


I posted my working code (simplified) on the thread i linked above...

FYI - I've been banging my head all day, and this worked for me. Is there something to be done to get around the need to remember to make this change? This was a pre-exising ASP.NET app to which I'm adding AJAX functionality.

Thanks!

rojay12:

Dude, found it!!!

change this...


<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class

TO

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class AjaxServices
Inherits System.Web.Services.WebService

End Class