Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with webservice

Status
Not open for further replies.

andym0908

Programmer
Feb 25, 2008
19
GB
Hi

I'm using .NET with the Ajax Control Toolkit, and I'm trying to get working the CascadingDropDown control.

Unforunately, to get it working via a SQL database like I need it to, it needs to use a webservice... and this is a new thing for me.

In VS I've created a .ASMX file (the web service file), and I've copied most of the code from a tutorial I'm following here.

My question is what do I put in as the namespace?

I'm confused by this... My webservice code I've got so far is below:-

Code:
<%@ WebService Language="C#" Class="pduk" %>

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;
using pdukdataTableAdapters;

    [WebService(Namespace = "what goes here?")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ProductData : System.Web.Services.WebService
    {
      public ProductData()
      {
        //Uncomment the following line if using designed components 
        //InitializeComponent();
      }

      [WebMethod]
      public CascadingDropDownNameValue[] GetSubProducts(
        string knownCategoryValues,
        string category)
      {
         
        pdukdataTableAdapters.pduk_fetchSubProductsTableAdapter SubProducts = 
            new pdukdataTableAdapters.pduk_fetchSubProductsTableAdapter();

        pdukdata.pduk_fetchSubProductsDataTable subproducts = SubProducts.GetSubProducts(1);

        //CarsTableAdapters.MakeTableAdapter makeAdapter = new CarsTableAdapters.MakeTableAdapter();
        //Cars.MakeDataTable makes = makeAdapter.GetMakes();
          
        List<CascadingDropDownNameValue> values =
          new List<CascadingDropDownNameValue>();
        foreach (DataRow dr in subproducts)
        {
          string strSubProductName = (string)dr["name"];
          int intSubProductUID = (int)dr["subproduct_uid"];
          values.Add(new CascadingDropDownNameValue(strSubProductName,intSubProductUID.ToString()));
        }
        return values.ToArray();
      }

    }
 
So, the ASMX file is the actual Webservice?

If so, the namespace value would be pointing to itself?

Right now, my project is just being run from within the Visual Studio 2008/Websites folder... is this a path I would reference?
 
You don't even HAVE to do it. Namespaces aren't required, but are helpful.
 
Ok, still having problems. I'm getting a Method Error 500 here, and I have no idea why. I'm simply developing this web app locally, although the db is remote.

Here's the Ajax control (CascadingDropDown) code from my .aspx file (yes, I have the script manager on the page, and it's also a master page):-

Code:
<AJX:CascadingDropDown ID="sss_prodSelect" runat="server" 
                PromptText="...Select Product..." LoadingText="Loading Values" Category="Product" 
                TargetControlID="sss_products" ServicePath="pduk.asmx" ServiceMethod="GetProducts">
                </AJX:CascadingDropDown>

                <asp:DropDownList ID="sss_products" runat="server">
                </asp:DropDownList>

..and here's the full .asmx file:-
Code:
<%@ WebService Language="C#" Class="pduk" %>

using System;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;
using pdukdataTableAdapters;


    [ScriptService]
    [WebService(Namespace = "[URL unfurl="true"]http://tempuri.org/")[/URL]]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ProductData : System.Web.Services.WebService
    {
        
      public ProductData()
      {
        //Uncomment the following line if using designed components 
        //InitializeComponent();
      }


      [WebMethod]
      public CascadingDropDownNameValue[] GetProducts(
          string knownCategoryValues,
          string category)
      {
          pdukdataTableAdapters.pduk_fetchPrintProductsTableAdapter prodMenu =
              new pdukdataTableAdapters.pduk_fetchPrintProductsTableAdapter();
          pdukdata.pduk_fetchPrintProductsDataTable products = prodMenu.GetProducts();

          List<CascadingDropDownNameValue> values =
          new List<CascadingDropDownNameValue>();

            //foreach (DataRow dr in products)
            //{
              //string strProductName = (string)dr["name"];
              //int intProductUID = (int)dr["product_uid"];
             //values.Add(new CascadingDropDownNameValue(strProductName,intProductUID.ToString()));
            //}
          
            values.Add(new CascadingDropDownNameValue("test","test"));
          
            return values.ToArray();
        }


 

      [WebMethod]
      public CascadingDropDownNameValue[] GetSubProducts(
        string knownCategoryValues,
        string category)
      {
         
        pdukdataTableAdapters.pduk_fetchSubProductsTableAdapter SubProducts = 
            new pdukdataTableAdapters.pduk_fetchSubProductsTableAdapter();

        pdukdata.pduk_fetchSubProductsDataTable subproducts = SubProducts.GetSubProducts(1);
          
        List<CascadingDropDownNameValue> values =
          new List<CascadingDropDownNameValue>();

        foreach (DataRow dr in subproducts)
        {
          string strSubProductName = (string)dr["name"];
          int intSubProductUID = (int)dr["subproduct_uid"];
          values.Add(new CascadingDropDownNameValue(strSubProductName,intSubProductUID.ToString()));
        }
        return values.ToArray();
      }

    }
 
No errors in Visual Studio, but the drop down is showing the error "Method Error 500"...
 
Ok I think I fixed it. I had the wrong class name in the <@ declaration at the top of the page! The class name is ProductData, not PDUK!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top