Hi,
This is relaated to VS2005.
I have a default.aspx page. on a button event I have called a webservice ProductService.asmx. The code on the button event is like this..
Protected Sub btnCategory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCategory.Click
Dim obj As New localhost.ProductsService
If txtCatName.Text = "" Then
Label1.ForeColor = Drawing.Color.Red
Label1.Text = "Please Select a option and enter a valid Category Name or Product Id"
Exit Sub
End If
'Dim objps As ProductsService
'objps = New ProductsService
If optbycatname.Checked = True Then
dgrdProducts.DataSource = obj.GetCategories(txtCatName.Text.Trim())
dgrdProducts.DataBind()
ElseIf optbyprdid.Checked = True Then
dgrdProducts.DataSource = obj.getProducts(txtCatName.Text.Trim())
dgrdProducts.DataBind()
End If
End Sub
The webservice code is as below:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration.ConfigurationManager
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicPr ofile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.Des ignerGenerated()> _
Public Class ProductsService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetCategories(ByVal categoryname As String) As DataSet
Dim conn As New SqlConnection("data source=192.168.1.10;integrated security=SSPI;persist security info=True;Database=northwind")
'Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrin gs("connstr").ToString())
Dim adap As SqlDataAdapter
Dim ds As New DataSet
Dim strSelect As String
strSelect = "SELECT ProductName 'Product Name', UnitPrice 'Unit Price', UnitsInStock 'Available Stock', CategoryName 'Category Name' " & _
"FROM Products, Categories WHERE Products.CategoryID = " & _
"Categories.CategoryID AND CategoryName = '" & categoryname & "'"
adap = New SqlDataAdapter(strSelect, conn)
adap.Fill(ds, "products")
Return ds
End Function
<WebMethod()> _
Public Function getProducts(ByVal productid As Integer) As DataSet
Dim conn As New SqlConnection("data source=192.168.1.10;integrated security=SSPI;persist security info=True;Database=northwind")
Dim adap As SqlDataAdapter
Dim ds As New DataSet
Dim strSelect As String
strSelect = "SELECT ProductName 'Product Name', UnitPrice 'Unit Price', UnitsInStock 'Available Stock', CategoryName 'Category Name' " & _
"FROM Products, Categories WHERE Products.CategoryID = " & _
"Categories.CategoryID AND productid = " & productid
adap = New SqlDataAdapter(strSelect, conn)
adap.Fill(ds, "products")
Return ds
End Function
End Class
When I run in the local machine it runs fine. But when I put it in the Web Server and access the page it gives the below error.
Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30002: Type 'ProductsService' is not defined.
Source Error:
Line 31: Exit Sub
Line 32: End If
Line 33: Dim objps As ProductsService
Line 34: objps = New ProductsService
Line 35: If optbycatname.Checked = True Then
Source File: D:\users\Padmajamvl\arete\www\webservice\Default.a spx.vb Line: 33
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
What am i doing wrong?
Please help..