本文介绍了需要帮助WebService ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的网页运行网络服务,我遇到了一些问题。 web服务用于填充第二个下拉列表。当从第一个下拉列表中选择一个项目时,它会调用GetTerritories。

GetTerritories调用Web服务TerritoriesService.GetTerritoriesInRegion。



但我是收到指定未定义TerritoriesService的错误。似乎Javascript函数找不到TerritoriesService。关于缺少什么的想法?

我附上了下面的网络服务。

I'm trying to run a webservice from my web page and I'm having a little problem. The webservice is used to populate a second dropdownlist. When an item is selected from the first dropdownlist it calls GetTerritories.
GetTerritories calls the web service TerritoriesService.GetTerritoriesInRegion.

But I’m getting an error specifying "TerritoriesService not defined". It appears that the Javascript function can’t find TerritoriesService. Any ideas as to what’s missing?
I enclosed the web service below.

<asp:DropDownList ID="lstRegions" Runat="server" Width="210px" 

          DataTextField="label_type" 

          DataValueField="label_type_id" 

          onChange="GetTerritories(this.value);">

<asp:DropDownList ID="lstTerritories" Runat="server" Width="275px">


 function GetTerritories(label_type_id) {

    TerritoriesService.GetTerritoriesInRegion(label_type_id,
    OnRequestComplete, OnError);
}




//
// this is the web service I'm trying to call
//

using System;
using System.Linq;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;

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

    [WebMethod()]
    public List<territory> GetTerritoriesInRegion(int label_type_id)
    {
        SqlConnection con = new SqlConnection(
          WebConfigurationManager.ConnectionStrings["Engineering"].ConnectionString);
        SqlCommand cmd = new SqlCommand(
            "SELECT * FROM tblMLPLabelDescription WHERE label_type_id=@label_type_id", con);
        cmd.Parameters.Add(new SqlParameter("@label_type_id", SqlDbType.Int, 4));
        cmd.Parameters["@label_type_id"].Value = label_type_id;

        List<territory> territories = new List<territory>();
        try
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                territories.Add(new Territory(
                  reader["TerritoryID"].ToString(),
                  reader["TerritoryDescription"].ToString()));
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            // Mask errors.
            throw new ApplicationException("Data error.");
        }
        finally
        {
            con.Close();
        }
        return territories;
    }
}

public class Territory
{
    public string ID;
    public string Description;

    public Territory(string id, string description)
    {
        this.ID = id;
        this.Description = description;
    }

    public Territory() { }
}

推荐答案



这篇关于需要帮助WebService ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 07:00