11

The code below gives me this error:

'JsonWcfService.GetVenues' does not implement interface member 'GetVenuesByLocation(string search)'.

I am fairly new to C# and .NET so most of this is copy and paste.

IGetVenues.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
 
namespace JsonWcfService
{
    [ServiceContract]
    public interface IGetVenues
    {
        [OperationContract]
        //attribute for returning JSON format
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/Venues/search={search}")]
        //method
        List<Venue> GetAllVenuesMethod(string search);
 
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/Venues/location={search}")]
        List<Venueloc> GetVenuesByLocation(string search); 
    }
}

GetVenues.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data.SqlClient;
namespace JsonWcfService
{
    public class GetVenues : IGetVenues 
    {
        public List<Venue> GetAllVenuesMethod(string search)
        {
            List<Venue> mylist = new List<Venue>();
 
            using (SqlConnection conn = new SqlConnection("server=*****;database=******;Trusted_Connection=True;"))
            {
                conn.Open();
                string cmdStr = String.Format("Select id,name,address1,town,postcode,lon,lat from venuesearch WHERE searchterm like @searchterm");
                SqlCommand cmd = new SqlCommand(cmdStr, conn);
                cmd.Parameters.Add(new SqlParameter("searchterm", "%" + Convert.ToString(search) + "%"));
                SqlDataReader rd = cmd.ExecuteReader();
                if (rd.HasRows)
                {
                    while (rd.Read())
                        mylist.Add(new Venue(
                            rd.GetInt32(0),
                            //rd.GetString(1),
                            rd.IsDBNull(1) ? null : rd.GetString(1),
                            //rd.GetString(2), 
                            rd.IsDBNull(2) ? null : rd.GetString(2),
                            //rd.GetString(3),
                            rd.IsDBNull(3) ? null : rd.GetString(3),
                            //rd.GetString(4)
                            rd.IsDBNull(4) ? null : rd.GetString(4),
                            //rd.GetString(4)
                            rd.IsDBNull(5) ? 0 : rd.GetDecimal(5),
                            //rd.GetString(4)
                            rd.IsDBNull(6) ? 0 : rd.GetDecimal(6)
                            ));
                }
                conn.Close();
            }
 
            return mylist;
        }
    }
 
    [DataContract]
 
    public class Venue
    {
        [DataMember]
        public Int32 id { get; set; }
        [DataMember]
        public string name { get; set; }
        [DataMember]
        public string address1 { get; set; }
        [DataMember]
        public string town { get; set; }
        [DataMember]
        public string postcode { get; set; }
        [DataMember]
        public Decimal lon { get; set; }
        [DataMember]
        public Decimal lat { get; set; }
        public Venue(int venid, string venname, string venaddress1, string ventown, string venpostcode, decimal venlon, decimal venlat)
        {
            id = venid;
            name = venname;
            address1 = venaddress1;
            town = ventown;
            postcode = venpostcode;
            lon = venlon;
            lat = venlat;
 
        }
 
        public List<Venueloc> GetVenuesByLocation(string search)
        {
            List<Venueloc> mylist = new List<Venueloc>();
 
            using (SqlConnection conn = new SqlConnection("server=***;database=******;Trusted_Connection=True;"))
            {
                conn.Open();
                string cmdStr = String.Format("Select id,name,address1,town,postcode,lon,lat from venuesearch WHERE searchterm like @searchterm");
                SqlCommand cmd = new SqlCommand(cmdStr, conn);
                cmd.Parameters.Add(new SqlParameter("searchterm", "%" + Convert.ToString(search) + "%"));
                SqlDataReader rd = cmd.ExecuteReader();
                if (rd.HasRows)
                {
                    while (rd.Read())
                        mylist.Add(new Venueloc(
                            rd.GetInt32(0),
                            //rd.GetString(1),
                            rd.IsDBNull(1) ? null : rd.GetString(1),
                            //rd.GetString(2), 
                            rd.IsDBNull(2) ? null : rd.GetString(2),
                            //rd.GetString(3),
                            rd.IsDBNull(3) ? null : rd.GetString(3),
                            //rd.GetString(4)
                            rd.IsDBNull(4) ? null : rd.GetString(4),
                            //rd.GetString(4)
                            rd.IsDBNull(5) ? 0 : rd.GetDecimal(5),
                            //rd.GetString(4)
                            rd.IsDBNull(6) ? 0 : rd.GetDecimal(6)
                            ));
                }
                conn.Close();
            }
 
            return mylist;
        }
    }
 
    [DataContract]
 
    public class Venueloc
    {
        [DataMember]
        public Int32 id { get; set; }
        [DataMember]
        public string name { get; set; }
        [DataMember]
        public string address1 { get; set; }
        [DataMember]
        public string town { get; set; }
        [DataMember]
        public string postcode { get; set; }
        [DataMember]
        public Decimal lon { get; set; }
        [DataMember]
        public Decimal lat { get; set; }
        public Venueloc(int venid, string venname, string venaddress1, string ventown, string venpostcode, decimal venlon, decimal venlat)
        {
            id = venid;
            name = venname;
            address1 = venaddress1;
            town = ventown;
            postcode = venpostcode;
            lon = venlon;
            lat = venlat;
 
        }
    }
}

The first function works but the second one doesn't.

Andreas
  • 5,393
  • 9
  • 44
  • 53
Jason Wragg
  • 589
  • 2
  • 5
  • 19

2 Answers2

6

Your class GetVenues does not implement the method mentioned in your error message. Where exactly are you stuck? GetVenuesByLocation(string search) is defined in the class Venue.

I have noticed that this question is starting to garner interest. The issue here is very easy: your class does not implement (even if it's abstract, you have to define them) all methods defined in the interface. Your IDE should warn you of this before compiling.

Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
  • Where do i need to put it to not get the error if i move it down i get even more errors. – Jason Wragg Aug 17 '13 at 16:44
  • 1
    You have to move that method to the class `GetVenues`. Horrible class name by the way. – Jeroen Vannevel Aug 17 '13 at 16:45
  • Thank you ! with your help i managed to get my head round it! – Jason Wragg Aug 17 '13 at 16:56
  • Have to agree with Jeroen, in this situation you would normally have a IVenueService , impelemnted by VenueService, which contains a Methode GetAllVenues, a class is a grouping of similar data and functions , get and set imply action so should only be used tor naming functions that perform the action, in this case your single function does the getting and your class is a group of functions and data (all be it a group which currently only contains 2 functions and no data) relating to making a service for venues – MikeT Feb 13 '14 at 15:38
2

Second function is inside the class Venue not in GetVenues, move it to GetVenues

Alessandro D'Andria
  • 8,663
  • 2
  • 36
  • 32