Reputation: 209
I have created a webservice in Visual studio 2010.I have created a database with a table which contains commands and their description.My program is: My class:-DataHelper.cs
using System;
using System.Data;
using System.Configuration;
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;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DataHelper
/// </summary>
public class DataHelper
{
public static string GetData(string Command)
{
string Explanation = " ";
SqlConnection con = new SqlConnection(@"Data Source=CSS-L3-D008;Initial Catalog=works1;Integrated Security=true;");
SqlCommand cmd = new SqlCommand("Select Explanation from Data1 where Command= '" + Command.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Explanation = dr["Explanation"].ToString();
}
dr.Close();
con.Close();
return Explanation;
}
}
And Service1.asmx
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
Private Property DataHelper As Object
<WebMethod()>
Public Function HelloWorld() As String
Return "Hello World"
End Function
<WebMethod()>
Public Function GetData(Command) As String
Return DataHelper.GetData(Command)
End Function
End Class
the problem is that wen i run it i am getting both webmethods HelloWorld and GetData but GetData is not working.When i click HelloWorld() i get invoke method and it runs properly.But when i click GetData() i get invoke button but then it shows "The test form is only available for methods with primitive types as parameters." Actually it should give a box where i can enter the command and the description should be returned from the sql server.Please help me.
Upvotes: 1
Views: 681
Reputation: 4042
Should that GetData method in the service declare the type of the Command parameter?:
<WebMethod()>
Public Function GetData(Command As String) As String
Return DataHelper.GetData(Command)
End Function
Upvotes: 1