我可以在一个webservice类中使用多个web方法吗?

问题描述:

我的Web服务GETcompletion1没有触发代码,就像这样

My webservice GETcompletion1 is not firing the code is somthing like this

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

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
    public AutoComplete()
    {
    }

    [WebMethod]
    public string[] GetCompletionList(string prefixText, int count)
  {
        if (count == 0)
        {
            count = 10;
        }
        DataTable dt = GetRecords(prefixText);
        List<string> items = new List<string>(count);

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string strName = dt.Rows[i][0].ToString();
            items.Add(strName);
            
        }
        return items.ToArray();
    }

    public DataTable GetRecords(string strName)
    {
        DataSet objDs = new DataSet();
        
            SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=medicalvoyager;Integrated Security=True");
            //con.Open();
            //SqlCommand cmd = new SqlCommand();
            //cmd.Connection = con;
            //cmd.CommandType = System.Data.CommandType.Text;
            SqlCommand com = new SqlCommand("Select Group_name from groups where Group_name like '%'+@Name+'%'  ",con);
            //cmd.CommandText = "Select Group_name from groups where Group_name like '%'+@Name+'%'";
           com.Parameters.AddWithValue("@Name", strName);
            SqlDataAdapter dAdapter = new SqlDataAdapter();
            dAdapter.SelectCommand = com;
            con.Open();
            dAdapter.Fill(objDs);
            con.Close();
        return objDs.Tables[0];   
        }
    [WebMethod]
    public string[] GetCompletionList1(string prefixText,int count)
    {
        if (count == 0)
        {
            count = 10;
        }
        DataTable dt = GetRecords1(prefixText);
        List<string> items1 = new List<string>(count);

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string strName = dt.Rows[i][0].ToString();
            items1.Add(strName);

        }
        return items1.ToArray();
    }

    public DataTable GetRecords1(string strName)
    {
        DataSet objDs = new DataSet();

        SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=medicalvoyager;Integrated Security=True");
        con.Open();
       // SqlCommand cmd = new SqlCommand();
       // cmd.Connection = con;
       // cmd.CommandType = System.Data.CommandType.Text;
        SqlCommand com = new SqlCommand("Select mvc_countryname from medvoyager_country where mvc_countryname like '%'+@Name+'%' ", con);
       // cmd.CommandText = "Select Group_name from groups where Group_name like '%'+@Name+'%'";
        com.Parameters.AddWithValue("@Name", strName);
        SqlDataAdapter dAdapter = new SqlDataAdapter();
        dAdapter.SelectCommand = com;
        con.Open();
        dAdapter.Fill(objDs);
        con.Close();
        return objDs.Tables[0];
    }


    }





so is it the problem with webmetod?

我可以在一个webservice类中使用多个web方法吗?
是的,单个Web服务中可以有多个WebMethod.

我的网络服务GETcompletion1没有触发代码
您确定已更新Web项目中的WebService参考吗?这是指最新代码吗?
尝试使用Visual Studio DEBUGGER,将中断点放在工作流起点上,然后执行F11键以查看情况如何.如果您不熟悉该方法,则很可能您的Web参考不是最新的(假定所有其他实现和方法调用均已正确完成).

检查!
Can I use more than one web method in a single webservice class
Yes, you can have multiple WebMethods in a single web service.

My webservice GETcompletion1 is not firing the code
You sure that you updated the WebService reference in your web project? Is that referring to latest code?
Try Visual Studio DEBUGGER, put break point on the workflow start point and then do F11 to see how things are happening. If you don''t land up in the method, most probably your web reference is not up-to-date (assuming all other implementation and method call are correctly done).

Check!


我可以在单个Web服务类中使用多个Web方法

是的,单个Web服务类中可以有多个WebMethod.

我的网络服务GETcompletion1无法启动

没有称为GETcompletion1 的Web方法,您需要调用GetCompletionList1,将断点放在方法内部,并检查是否触发,并且最好进行异常处理.

您可以遵循的几个步骤.

清洁解决方案并删除Web参考.
再次添加Web参考并构建解决方案.
如果有任何构建错误,请修复这些错误并检查在AutoCompleteExtender
中作为ServiceMethod<code> ServicePath给出的错误
ServiceMethod ="GetCompletionList1" ServicePath =〜/YourWebService.asmx"
Can I use more than one web method in a single webservice class

Yes, You can have more than one WebMethod in single webservice class.

My webservice GETcompletion1 is not firing

there is no web method called GETcompletion1 you need to call GetCompletionList1, Put break point inside the method and check whether it firing or not and also better to have exception handling.

Few steps you can follow.

Clean the solution and delete the web reference.
Add the web reference again and build the solution.
If any build errors, fix those and check what you have given as ServiceMethod and <code>ServicePath in AutoCompleteExtender

ServiceMethod="GetCompletionList1" ServicePath="~/YourWebService.asmx"


是的,您可以添加此代码来完成以下工作
yes u can add this code for doing following work done
using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
    public AutoComplete()
    {
    }
 
    [WebMethod]
    public string[] GetCompletionList(string prefixText, int count)
  {
        if (count == 0)
        {
            count = 10;
        }
        DataTable dt = GetRecords(prefixText);
        List<string> items = new List<string>(count);
 
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string strName = dt.Rows[i][0].ToString();
            items.Add(strName);
            
        }
        return items.ToArray();
    }
 
    public DataTable GetRecords(string strName)
    {
        DataSet objDs = new DataSet();
        
            SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=medicalvoyager;Integrated Security=True");
            //con.Open();
            //SqlCommand cmd = new SqlCommand();
            //cmd.Connection = con;
            //cmd.CommandType = System.Data.CommandType.Text;
            SqlCommand com = new SqlCommand("Select Group_name from groups where Group_name like '%'+@Name+'%'  ",con);
            //cmd.CommandText = "Select Group_name from groups where Group_name like '%'+@Name+'%'";
           com.Parameters.AddWithValue("@Name", strName);
            SqlDataAdapter dAdapter = new SqlDataAdapter();
            dAdapter.SelectCommand = com;
            con.Open();
            dAdapter.Fill(objDs);
            con.Close();
        return objDs.Tables[0];   
        }
    [WebMethod]
    public string[] GetCompletionList1(string prefixText,int count)
    {
        if (count == 0)
        {
            count = 10;
        }
        DataTable dt = GetRecords1(prefixText);
        List<string> items1 = new List<string>(count);
 
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string strName = dt.Rows[i][0].ToString();
            items1.Add(strName);
 
        }
        return items1.ToArray();
    }
 
    public DataTable GetRecords1(string strName)
    {
        DataSet objDs = new DataSet();
 
        SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=medicalvoyager;Integrated Security=True");
        con.Open();
       // SqlCommand cmd = new SqlCommand();
       // cmd.Connection = con;
       // cmd.CommandType = System.Data.CommandType.Text;
        SqlCommand com = new SqlCommand("Select mvc_countryname from medvoyager_country where mvc_countryname like '%'+@Name+'%' ", con);
       // cmd.CommandText = "Select Group_name from groups where Group_name like '%'+@Name+'%'";
        com.Parameters.AddWithValue("@Name", strName);
        SqlDataAdapter dAdapter = new SqlDataAdapter();
        dAdapter.SelectCommand = com;
        con.Open();
        dAdapter.Fill(objDs);
        con.Close();
        return objDs.Tables[0];</string></string></string></string>