ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Call Business Layer class method inside Web Service in ASP.Net using C# and VB.Net<p>Hi <a class="username" rel="nagaraju60">nagaraju60</a>,</p> <p>You just create a class and return List from the class, then call the class in Web Service.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">DataAccess.cs</span></strong></p> <pre class="brush: csharp">public List&lt;string&gt; GetCustomerIds(string prefixText) { System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ToString()); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(&#34;select ContactName,CustomerId from Customers where ContactName like @SearchText + &#39;%&#39;&#34;, con); cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue(&#34;@SearchText&#34;, prefixText); con.Open(); List&lt;string&gt; customerIds = new List&lt;string&gt;(); using (System.Data.SqlClient.SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr[&#34;ContactName&#34;].ToString(), sdr[&#34;CustomerId&#34;].ToString()); customerIds.Add(item); } sdr.Close(); } con.Close(); return customerIds; }</pre> <p><strong><span style="text-decoration: underline;">DataAccess.vb</span></strong></p> <pre class="brush: vb">Public Function GetCustomerIds(ByVal prefixText As String) As List(Of String) Dim con As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ToString()) Dim cmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(&#34;select ContactName,CustomerId from Customers where ContactName like @SearchText + &#39;%&#39;&#34;, con) cmd.CommandType = System.Data.CommandType.Text cmd.Parameters.AddWithValue(&#34;@SearchText&#34;, prefixText) con.Open() Dim customerIds As List(Of String) = New List(Of String)() Using sdr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader() While sdr.Read() Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr(&#34;ContactName&#34;).ToString(), sdr(&#34;CustomerId&#34;).ToString()) customerIds.Add(item) End While sdr.Close() End Using con.Close() Return customerIds End Function</pre> <p><strong><span style="text-decoration: underline;">asmx webservice</span></strong></p> <p><strong>CS</strong></p> <pre class="brush: csharp">[WebMethod] public List&lt;string&gt; SearchUsrId(string prefixText, int count) { DataAccess data = new DataAccess(); List&lt;string&gt; Usr_Id = data.GetCustomerIds(prefixText); return Usr_Id; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">&lt;WebMethod&gt; Public Function SearchUsrId(ByVal prefixText As String, ByVal count As Integer) As List(Of String) Dim data As DataAccess = New DataAccess() Dim Usr_Id As List(Of String) = data.GetCustomerIds(prefixText) Return Usr_Id End Function</pre> <p>Then call the web service in aspx page.</p>https://www.aspforums.net:443/Threads/343772/Call-Business-Layer-class-method-inside-Web-Service-in-ASPNet-using-C-and-VBNet/https://www.aspforums.net:443/Threads/343772/Call-Business-Layer-class-method-inside-Web-Service-in-ASPNet-using-C-and-VBNet/Mon, 02 Apr 2018 02:46:17 GMT