Saturday, March 24, 2012

A simple question: Do webservices work with the beta?

I can't seem to get of my webservice to work. All I get is object undefined. I have javascript that gets triggered on an onblur() event which calls a webservice where the code is in another file. Nothing I do will get it to work. I've tried all the solutions I've found and still errors.

Same goes for cascadingdropdowns. It's like my webservice is invisible. I read the sticky about putting the webservice call in the aspx file and I did that but it still can't be found.

I find that the documentation is limited and what I do find, it seems to be written for experts. So, I guess for now, I have no option but to dump the path I'm on since it appears to me the code isn't ready for beta. Too many issues. Not enough documentation and examples.

Very frustrated!

Hi jax67, can we see the webservice class and the javascript function that calls it? Also the error message that you are getting. Maybe I can help. I used cascadingdropdowns a lot too, it was very frustated at first, but then I figured it out. So, everything is all good now.

Thanks AW - I am so frustrated :( The first file is in a folder called Maint (off of the root) and the webservice asmx file is in the root. The code for the webservice is in app_code.

Here is the code that has the javascript call. The onblur is what calls the javascript and that part works. It's the actual call to the service that fails. I put an alert before the call and the alert is displayed. A javascript error occurs after I dismiss the alert. I do not have the alert code in the following code files.

Thank you for any help you can provide. I really do appreciate it...

Dave

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="Amendment.aspx.cs" Inherits="Maint_Amendment" Title="Add A New Contract Amendment"
EnableEventValidation="false" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<ajax:ScriptManager ID="sm" runat="server" EnablePartialRendering="True">
<Services>
<ajax:ServiceReference Path="../ContractService.asmx"/>
</Services>
</ajax:ScriptManager>
<script type="text/javascript" language="javascript">
function AddDates_click()
{
// Get the values necessary to pass to the webservice
var startDate = $get('<%= txtStartDate.ClientID %>').value;

var periodInYears = $get('<%= txtPeriodYears.ClientID %>').value;
if (periodInYears == "") periodInYears = "0";

var periodInMonths = $get('<%= txtPeriodMonths.ClientID %>').value;
if (periodInMonths == "") periodInMonths = "0";

if (startDate != "")
{
// Show the progress and resize the textbox
document.getElementById('calculating').style.display = '';
$get('<%= txtExpirationDate.ClientID %>').style.width = '90%';
// Make the call to the webservice
alert("Before Call...");
var x = ContractService.CalculateExpirationDate(startDate, periodInYears, periodInMonths, OnComplete, OnTimeout);
}

return false;
}
function OnComplete(result)
{
$get('<%= txtExpirationDate.ClientID %>').value = result;
document.getElementById('calculating').style.display = 'none';
$get('<%= txtExpirationDate.ClientID %>').style.width = '98%';
}
function OnTimeout(result)
{
document.getElementById('calculating').style.display = 'none';
$get('<%= txtExpirationDate.ClientID %>').style.width = '98%';
}
</script>
<ajax:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="http://pics.10026.com/?src=../images/spinner.gif" />
</ProgressTemplate>
</ajax:UpdateProgress>
<ajax:UpdatePanel ID="upAmendment" runat="server">
<ContentTemplate>
<table align="center" border="1" bordercolor="#000000" cellpadding="4" style='width: 50%;
border-collapse: collapse">
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label2" runat="server" SkinID="bold" Text="Amendment Num"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtAmendmentNumber" runat="server" MaxLength="10" ReadOnly="True"></asp:TextBox><br />
<asp:TextBox ID="txtContract" runat="server" ReadOnly="True" Visible="False"></asp:TextBox></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="lblStartDate" runat="server" SkinID="bold" Text="Start Date"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtStartDate" runat="server" MaxLength="15" onblur="return AddDates_click()"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtStartDate"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regStartDate" runat="server" ControlToValidate="txtStartDate"
Display="Dynamic" ErrorMessage="Invalid Date Format"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label3" runat="server" SkinID="bold" Text="Period (Years)"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtPeriodYears" runat="server" MaxLength="3" onblur="return AddDates_click()"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngYears" runat="server" ControlToValidate="txtPeriodYears"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="100" MinimumValue="1"
Type="Integer" SetFocusOnError="True"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label4" runat="server" SkinID="bold" Text="Period (Months)"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtPeriodMonths" runat="server" MaxLength="2" onblur="return AddDates_click()"
AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtPeriodMonths"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="11" MinimumValue="0"
SetFocusOnError="True" Type="Integer"></asp:RangeValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label5" runat="server" SkinID="bold" Text="Expiration Date"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtExpirationDate" TabIndex="-1" runat="server" MaxLength="15"></asp:TextBox>
<span id="calculating" style='display: none;'>
<img src="http://pics.10026.com/?src=../images/spinner.gif" /></span>
</td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label11" runat="server" SkinID="bold" Text="Class"></asp:Label></td>
<td class="alt">
<asp:DropDownList ID="ddlClass" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqClass" runat="server" ControlToValidate="ddlClass"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label12" runat="server" SkinID="bold" Text="Type Of"></asp:Label></td>
<td class="alt">
<asp:DropDownList ID="ddlType" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqType" runat="server" ControlToValidate="ddlType"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label6" runat="server" SkinID="bold" Text="Consideration"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtConsideration" runat="server" MaxLength="10" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngConsideration" runat="server" ControlToValidate="txtConsideration"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="999999999" MinimumValue="0"
SetFocusOnError="True" Type="Double"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label7" runat="server" SkinID="bold" Text="Percent of Credit"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtPercentCredit" runat="server" MaxLength="30" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngPercentCredit" runat="server" ControlToValidate="txtPercentCredit"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="100" MinimumValue="0"
SetFocusOnError="True" Type="Double"></asp:RangeValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label8" runat="server" SkinID="bold" Text="Credit Type"></asp:Label></td>
<td class="alt">
<asp:DropDownList ID="ddlCreditType" runat="server" DataTextField="LOV_ITEM" DataValueField="LOV_VALUE">
</asp:DropDownList></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label9" runat="server" SkinID="bold" Text="Carry Forward (Years)"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtCarryForward" runat="server" MaxLength="2" AutoCompleteType="Disabled"></asp:TextBox>
<asp:RangeValidator ID="rngCarryForward" runat="server" ControlToValidate="txtCarryForward"
Display="Dynamic" ErrorMessage="Invalid Value" MaximumValue="100" MinimumValue="0"
SetFocusOnError="True" Type="Integer"></asp:RangeValidator></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label10" runat="server" SkinID="bold" Text="Assignable ?"></asp:Label></td>
<td class="alt">
<asp:RadioButtonList ID="optAssignable" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList></td>
</tr>
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="lblEffectivityDate" runat="server" SkinID="bold" Text="Effectivity Date"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtEffectivityDate" runat="server" AutoCompleteType="Disabled" MaxLength="15"
onblur="return AddDates_click()"></asp:TextBox>
<asp:RegularExpressionValidator ID="regEffectivityDate" runat="server" ControlToValidate="txtEffectivityDate"
Display="Dynamic" ErrorMessage="Invalid Date Format"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="reqEffectivityDate" runat="server" ControlToValidate="txtEffectivityDate"
Display="Dynamic" ErrorMessage="This field is required"></asp:RequiredFieldValidator></td>
</tr>
</table>
<ajaxToolkit:CascadingDropDown ID="cddClass" runat="server" Category="Class" PromptText="Select a Class"
ServicePath="../ContractService.asmx" ServiceMethod="GetClasses" TargetControlID="ddlClass" Enabled="true" />
<ajaxToolkit:CascadingDropDown ID="cddType" runat="server" Category="Type" PromptText="Select a Type"
ServicePath="../ContractService.asmx" ServiceMethod="GetTypes" TargetControlID="ddlType" ParentControlID="ddlClass" Enabled="true" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmPeriodYears" runat="server" TargetControlID="txtPeriodYears" WatermarkCssClass="WaterMark" WatermarkText="Terms in years" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmPeriodMonths" runat="server" TargetControlID="txtPeriodMonths" WatermarkCssClass="WaterMark" WatermarkText="Terms in months" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmStartDate" runat="server" TargetControlID="txtStartDate" WatermarkCssClass="WaterMark" WatermarkText="Contract Start Date" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmConsideration" runat="server" TargetControlID="txtConsideration" WatermarkCssClass="WaterMark" WatermarkText="Amount paid or units mined in consideration" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmPercentCredit" runat="server" TargetControlID="txtPercentCredit" WatermarkCssClass="WaterMark" WatermarkText="% of credit received from payment" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmCarryForward" runat="server" TargetControlID="txtCarryForward" WatermarkText="Period in years credits may be carried forward" WatermarkCssClass="WaterMark" />
<ajaxToolkit:TextBoxWatermarkExtender ID="wmEffectivityDate" runat="server" TargetControlID="txtEffectivityDate" WatermarkCssClass="WaterMark" WatermarkText="When does this amendment take affect" />
</ContentTemplate>
</ajax:UpdatePanel>
<asp:Panel runat="server" ID="pnlReasonForEdit" SkinID="reasonforedit">
<br />
<table align="center" border="1" bordercolor="#000000" cellpadding="4" style='width: 50%;
border-collapse: collapse">
<tr>
<td class="label" style='width: 30%'>
<asp:Label ID="Label1" runat="server" SkinID="bold" Text="Reason for Edit"></asp:Label></td>
<td class="alt">
<asp:TextBox ID="txtReasonForEdit2" runat="server" MaxLength="2000" TextMode="MultiLine"
Rows="2"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqReasonForEdit" runat="server" ControlToValidate="txtReasonForEdit2"
Display="Dynamic" ErrorMessage="A reason must be entered" SetFocusOnError="True"></asp:RequiredFieldValidator></td>
</tr>
</table>
</asp:Panel>
<p align="center">
<asp:Button ID="cmdSave" runat="server" OnClick="cmdSave_Click" Text="Save" />
<asp:Button ID="cmdCancel" runat="server" CausesValidation="False" OnClick="cmdCancel_Click"
Text="Cancel" />
</p
<script type="text/javascript">
var styleToSelect;
function onOk() {
//$get('Paragraph1').className = styleToSelect;
}
</script
<asp:Panel ID="Panel1" runat="server" Style='display: none' Width='65%' SkinID='ReasonHeader'>
Please provide a reason for the edit
<asp:Panel ID="pnlBody" runat="server" SkinID="ReasonBody" Style='margin: 5px;'>
<br />
Enter the reason for editing this Amendment:
<asp:TextBox EnableTheming="false" runat="server" ID="txtReasonForEdit" TextMode="multiLine"
Width="96%" Rows="5"></asp:TextBox>
<br />
<br />
<center>
<asp:Button ID="OkButton" runat="server" Text="OK"></asp:Button>
<asp:Button ID="CancelButton" runat="server" Text="Cancel"></asp:Button>
</center>
<br />
</asp:Panel>
</asp:Panel>
</asp:Content>

Here is the Webservice file:

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Web.Script.Services;

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

public ContractService () {

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

[WebMethod]
public string GetNextContractSequence(string contract)
{
// ---------------------------
// Author: dzangger
// Company: Huber
// Date: 8/4/2006
// Time: 12:06
// Procedure Name: GetNextContractSequence
// Purpose: Get the next available sequence number for contract
// Parameters:
// - contract (string)() :
// ---------------------------
return contract.ToUpper() + CMSDB.GetNextContractSequence(contract.ToUpper());
}

[WebMethod]
public string DoesContractExist(string contract)
{
bool b = CMSDB.DoesContractExist(contract);

if (b)
return "~" + contract.ToUpper();
else
return contract.ToUpper();
}

[WebMethod]
public string GetIndexValue(string index, string beginDate, string endDate)
{
try
{
DateTime d = Convert.ToDateTime(beginDate);
d = Convert.ToDateTime(endDate);
}
catch (Exception)
{
return "";
}

return CMSDB.GetIndexValueFromDateRange(index, beginDate, endDate);
}

[WebMethod]
public string CalculateExpirationDate(string startDate, string years, string months)
{
// ---------------------------
// Author: dzangger
// Company: Huber
// Date: 8/3/2006
// Time: 13:21
// Procedure Name: CalculateExpirationDate
// Purpose: Adds a number of years and months to a given date
// Parameters:
// - startDate (string)() :
// - years (string)() :
// - months (string)() :
// ---------------------------
try
{
int iYears = 0, iMonths = 0;

try
{
iYears = Convert.ToInt16(years);
}
catch (Exception)
{
iYears = 0;
}

try
{
iMonths = Convert.ToInt16(months);
}
catch (Exception)
{
iMonths = 0;
}

DateTime date = Convert.ToDateTime(startDate);

if (iYears > 0)
date = date.AddYears(iYears);

if (iMonths > 0)
date = date.AddMonths(iMonths);

return date.ToShortDateString();
}
catch (Exception)
{
return "";
}
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetIndexTypes(string knownCategoryValues, string category)
{
// ---------------------------
// Author: david.zangger
// Company: Huber
// Date: 10/13/2006
// Time: 07:27
// Procedure Name: GetIndexTypes
// Purpose: Gets the indexes and their types
// Parameters:
// - knownCategoryValues (string)() :
// - category (string)() :
// ---------------------------
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

IDataReader reader = CMSDB.GetIndexesAndIndexTypes();

while (reader.Read())
{
string classId = reader[0].ToString();
string index = reader[1].ToString();
values.Add(new CascadingDropDownNameValue(classId, index));
}

reader.Close();

return values.ToArray();
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetIndexSeries(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

StringDictionary sd = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

if (sd.ContainsKey("Index"))
{
IDataReader reader = CMSDB.GetSeriesIds(sd["Index"].ToString());

while (reader.Read())
{
string series = reader[0].ToString();
values.Add(new CascadingDropDownNameValue(series, series));
}

reader.Close();

return values.ToArray();
}
else
return null;
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetClasses(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

IDataReader reader = CMSDB.GetContractClasses();

while (reader.Read())
{
string classId = reader[0].ToString();
values.Add(new CascadingDropDownNameValue(classId, classId));
}

reader.Close();

return values.ToArray();
}

[WebMethod]
[Microsoft.Web.Script.Services.ScriptMethod()]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetTypes(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

StringDictionary sd = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

if (sd.ContainsKey("Class"))
{
IDataReader reader = CMSDB.GetContractTypes(sd["Class"].ToString());

while (reader.Read())
{
string classId = reader[1].ToString();
string desc = reader[0].ToString();
values.Add(new CascadingDropDownNameValue(desc, classId));
}

reader.Close();

return values.ToArray();
}
else
return null;
}
}

I seem to have it working. I created a new website (using the CTP version) and then used the web.config from that project. I migrated my appsettings and an Oracle assembly and then moved my webservice in the folder where the files calling it resides. For now, I'm going to leave it as it is.

Thanks AW for your assistance!

dave

No comments:

Post a Comment