Click here to Skip to main content
15,887,683 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Telerik Vs Devexpress Pin
Richard MacCutchan23-May-13 5:20
mveRichard MacCutchan23-May-13 5:20 
GeneralRe: Telerik Vs Devexpress Pin
Mohamed_hussain23-May-13 18:01
Mohamed_hussain23-May-13 18:01 
GeneralRe: Telerik Vs Devexpress Pin
Jasmine250128-May-13 7:30
Jasmine250128-May-13 7:30 
GeneralRe: Telerik Vs Devexpress Pin
Richard MacCutchan28-May-13 11:16
mveRichard MacCutchan28-May-13 11:16 
QuestionRe: Telerik Vs Devexpress Pin
ZurdoDev24-May-13 4:29
professionalZurdoDev24-May-13 4:29 
AnswerRe: Telerik Vs Devexpress Pin
Mohamed_hussain24-May-13 18:17
Mohamed_hussain24-May-13 18:17 
AnswerRe: Telerik Vs Devexpress Pin
ZurdoDev28-May-13 2:20
professionalZurdoDev28-May-13 2:20 
QuestionWeb Services / Web References in ASP.NET using C# Pin
WickedFooker23-May-13 0:50
WickedFooker23-May-13 0:50 
I have no idea what I am wrong. Needless to say it is giving me a compiler error "Error 1 'clsWebServices' does not contain a definition for 'FindAddress' and no extension method 'FindAddress' accepting a first argument of type 'clsWebServices' could be found (are you missing a using directive or an assembly reference?)"

What do I need to do to make this Web Method / Web Reference work properly? This is for a local Access .mdb file that resides under app_Data.

This is what I have under App_Code for clsWebSerices.cs:
C#
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.OleDb;
using System.Web.Services;


/// <summary>
/// Summary description for clsWebServices
/// </summary>

public class clsWebServices : System.Web.Services.WebService {

    public clsWebServices () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]  
        public dsAddress FindAddress(string LastName, string Path)
        {
            
            
            string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path;
            string commandText = "select * from tblAddressBook where LastName like '" + LastName + "'";

            dsAddress DS = default(dsAddress);

            using (var connection = new OleDbConnection(connectionString))
            using (var command = new OleDbCommand(commandText, connection))
            {
                // OleDbCommand uses positional, rather than named, parameters.
                // The parameter name doesn't matter; only the position.
                DS = new dsAddress();
                var adapter = new OleDbDataAdapter(command);
                adapter.Fill(DS);
            }

            // Add your comments here
            return DS;

        }
        
    }
    
    
}


And for clsWebServices.asmx:
C#
<%@ WebService Language="C#" CodeBehind="~/App_Code/clsWebServices.cs" Class="clsWebServices" %>


frmAddressBook.aspx:
C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="frmAddressBook.aspx.cs" Inherits="frmAddressBook" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server" action="clsWebServices.asmx" method="post">
    <div>
    
        <asp:Label ID="Label1" runat="server" Text="Find Last Name: "></asp:Label>
        <asp:TextBox ID="txtFindLastName" runat="server"></asp:TextBox>
        <asp:Button ID="btnFindLastName" runat="server" Text="Search Now" 
            onclick="btnFindLastName_Click" />
        <br />
        <br />
        <br />
       
        <asp:Label 
             ID="lblMessage" runat="server" 
             Text="Search Result (first record to match)" Font-Size="XX-Large"></asp:Label>
         <br />
            <br />
            <asp:Label ID="Label2" runat="server" Text="First Name: "></asp:Label>
             
         <asp:TextBox ID="txtFirstName" runat="server" BackColor="#FFFFCC"></asp:TextBox>
         <br />
         <br />
         <asp:Label ID="Label3" runat="server" Text="Last Name: "></asp:Label>
     
         <asp:TextBox ID="txtLastName" runat="server" BackColor="#FFFFCC"></asp:TextBox>
         <br />
         <br />
         <asp:Label ID="Label4" runat="server" Text="Email: "></asp:Label>
            
         <asp:TextBox ID="txtEmail" runat="server" BackColor="#FFFFCC"></asp:TextBox>
         <br />
         <br />
         <asp:Label ID="Label5" runat="server" Text="Phone Number: "></asp:Label>
         <asp:TextBox ID="txtPhoneNumber" runat="server" BackColor="#FFFFCC"></asp:TextBox>
        </div>
    </form>
</body>
</html>


The code behind:
C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class frmAddressBook : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnFindLastName_Click(object sender, EventArgs e)
    {
        lblMessage.Text = "";
        try
        {
            clsWebServices serviceObj = new clsWebServices();
            dsAddress dsFindLastName = new dsAddress();
            string TempPath = Server.MapPath("~/App_Data/AddressBook.mdb");

            dsFindLastName = serviceObj.FindAddress(txtFindLastName.Text, TempPath);

            if (dsFindLastName.tblAddressBook.Rows.Count > 0)
            {
                DataRow r = dsFindLastName.tblAddressBook.Rows[0];
                txtFirstName.Text = r["FirstName"].ToString();
                txtLastName.Text = r["LastName"].ToString();
                txtEmail.Text = r["Email"].ToString();
                txtPhoneNumber.Text = r["PhoneNumber"].ToString();
            }
            else lblMessage.Text = "No records found!";
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
        }
    }
}


I have tried to add a WEB REFERENCE in VS2008 and it says :
This web service is using http://tempuri.org/ as its default namespace.
Recommendation: Change the default namespace before the XML Web service is made public.

C#
[WebService(Namespace="http://microsoft.com/webservices/")]
public class MyWebService {
    // implementation
}

AnswerRe: Web Services / Web References in ASP.NET using C# Pin
Richard Deeming23-May-13 1:41
mveRichard Deeming23-May-13 1:41 
GeneralRe: Web Services / Web References in ASP.NET using C# Pin
WickedFooker23-May-13 11:27
WickedFooker23-May-13 11:27 
GeneralRe: Web Services / Web References in ASP.NET using C# Pin
Richard Deeming24-May-13 1:42
mveRichard Deeming24-May-13 1:42 
GeneralRe: Web Services / Web References in ASP.NET using C# Pin
WickedFooker24-May-13 15:57
WickedFooker24-May-13 15:57 
Questionplease help me create form comment in asp.net mvc Pin
smile9x22-May-13 15:47
smile9x22-May-13 15:47 
AnswerRe: please help me create form comment in asp.net mvc Pin
dusty_dex22-May-13 21:06
dusty_dex22-May-13 21:06 
GeneralRe: please help me create form comment in asp.net mvc Pin
smile9x23-May-13 0:51
smile9x23-May-13 0:51 
QuestionStore string list Pin
byka21-May-13 7:53
byka21-May-13 7:53 
QuestionRe: Store string list Pin
ZurdoDev21-May-13 10:22
professionalZurdoDev21-May-13 10:22 
AnswerRe: Store string list Pin
Manfred Rudolf Bihy21-May-13 21:07
professionalManfred Rudolf Bihy21-May-13 21:07 
AnswerRe: Store string list Pin
poongunrans28-May-13 20:07
poongunrans28-May-13 20:07 
QuestionStart an async method inside an MVC action method. Pin
Brady Kelly21-May-13 6:43
Brady Kelly21-May-13 6:43 
Questionanyone plz tell me which is free version of iTextSharp library? Pin
manoj.jsm21-May-13 4:34
manoj.jsm21-May-13 4:34 
AnswerRe: anyone plz tell me which is free version of iTextSharp library? Pin
Thomas Daniels21-May-13 7:10
mentorThomas Daniels21-May-13 7:10 
QuestionMVC vs n-Tier Architecture Pin
Bikash Prakash Dash21-May-13 0:08
Bikash Prakash Dash21-May-13 0:08 
AnswerRe: MVC vs n-Tier Architecture Pin
Richard MacCutchan21-May-13 2:58
mveRichard MacCutchan21-May-13 2:58 
AnswerRe: MVC vs n-Tier Architecture Pin
Manfred Rudolf Bihy21-May-13 3:17
professionalManfred Rudolf Bihy21-May-13 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.