6 Months Free & No Setup Fees ASP.NET Hosting!
Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » WCF » Cannot add Service as ServiceReference in Silverlight Project
       
Author Reply
zoltan vatadi
posted 1 posts
since Sep 07, 2010 
from

Cannot add Service as ServiceReference in Silverlight Project

  Posted on: 09 Sep 2010       
Hi!

I tried to create a Silverlight-enabled WCF Service, but when i try to add it as a service reference to my project i always face an error.
Here's .cs file:

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;

namespace TODO.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    public class TODO_db_Service
    {
        public List<Users> SelectUsersWhere(string where)
        {

            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
            MySql.Data.MySqlClient.MySqlDataReader myData;
            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            List<Users> userlist = new List<Users>();

            string commandQuery = "Select userName, password, emailAddress FROM Users WHERE " + where + ";";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = commandQuery;

                myData = cmd.ExecuteReader();

                myData.Read();

                if (myData.HasRows)
                {
                    do
                    {
                        string userName = myData.GetString("userName").ToString();
                        string password = myData.GetString("password").ToString();
                        string emailAddress = myData.GetString("emailAddress").ToString();

                        Users instance = new Users();
                        instance.usernameField = userName;
                        instance.passwordField = password;
                        instance.emailField = emailAddress;

                        userlist.Add(instance);
                    } while (myData.Read());

                    myData.Close();
                    conn.Close();
                }
                myData.Close();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }
            return userlist;
        }

        public void InsertIntoUsers(string userName, string password, string emailAddress)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            string insertQuery = "INSERT INTO Users (userName, password, emailAddress) VALUES ('"
                + userName + "', '" + password + "', '" + emailAddress + "');";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = insertQuery;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }

        }

        public void InsertIntoProjects(string projectTitle, string description, string expirationDate, string assosiatedEmailAddress)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            string insertQuery;

            if (expirationDate == "null")
            {
                insertQuery = "INSERT INTO Projects (projectTitle, description, expirationDate, assosiatedEmailAddress) VALUES ('"
                   + projectTitle + "', '" + description + "', " + expirationDate + ", '" + assosiatedEmailAddress + "');";
            }
            else
            {
                insertQuery = "INSERT INTO Projects (projectTitle, description, expirationDate, assosiatedEmailAddress) VALUES ('"
                  + projectTitle + "', '" + description + "', '" + expirationDate + "', '" + assosiatedEmailAddress + "');";
            }
            conn.ConnectionString = connectionString;

            Console.WriteLine(insertQuery);

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = insertQuery;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }
        }

        public void InsertIntoTasks(string taskName, string description, string expirationDate,
                            string assosiatedEmailAddress, int assosiatedTaskId)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            string insertQuery;
            if (expirationDate == "null")
            {
                insertQuery = "INSERT INTO Tasks (taskName, description, expirationDate, assosiatedEmailAddress, assosiatedProjectId) VALUES ('"
                 + taskName + "', '" + description + "', " + expirationDate + ", '"
                 + assosiatedEmailAddress + "', '" + assosiatedTaskId + "');";
            }
            else
            {
                insertQuery = "INSERT INTO Tasks (taskName, description, expirationDate, assosiatedEmailAddress, assosiatedProjectId) VALUES ('"
                 + taskName + "', '" + description + "', '" + expirationDate + "', '"
                 + assosiatedEmailAddress + "', '" + assosiatedTaskId + "');";
            }




            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = insertQuery;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }
        }

        public string RegisterUser(string userName, string password, string emailAddress)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
            MySql.Data.MySqlClient.MySqlDataReader myData;

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            List<Users> userlist = new List<Users>();
            string where = "WHERE emailAddress LIKE '" + emailAddress + "'";
            string commandQuery = "Select userName, password, emailAddress FROM Users " + where + ";";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = commandQuery;

                myData = cmd.ExecuteReader();
                myData.Read();

                if (myData.HasRows)
                {
                    myData.Close();
                    conn.Close();

                    return "E-mail Address taken, choose a new one!";
                }
                else
                {
                    myData.Close();
                    conn.Close();
                    InsertIntoUsers(userName, password, emailAddress);

                    return "Registration completed!";
                }


            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }

            conn.Close();
            return "error";
        }

        public Users LoginUser(string emailAddress, string password)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
            MySql.Data.MySqlClient.MySqlDataReader myData;
            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            string where = "WHERE emailAddress LIKE '" + emailAddress + "' AND password LIKE '" + password + "'";

            string commandQuery = "Select userName, password, emailAddress FROM Users " + where + ";";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = commandQuery;

                myData = cmd.ExecuteReader();

                myData.Read();

                if (myData.HasRows)
                {
                    string db_userName = myData.GetString("userName").ToString();
                    string db_password = myData.GetString("password").ToString();
                    string db_emailAddress = myData.GetString("emailAddress").ToString();

                    Users instance = new Users();
                    instance.usernameField = db_userName;
                    instance.passwordField = db_password;
                    instance.emailField = db_emailAddress;

                    myData.Close();
                    conn.Close();
                    return instance;
                }

            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }

            conn.Close();
            return null;
        }

        public List<Tasks> SelectTasksWhere(string where)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
            MySql.Data.MySqlClient.MySqlDataReader myData;
            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            List<Tasks> list = new List<Tasks>();
            string commandQuery = "Select id, taskName, description, expirationDate, assosiatedEmailAddress, assosiatedProjectId FROM Tasks WHERE "
                                    + where + ";";
            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = commandQuery;

                myData = cmd.ExecuteReader();

                myData.Read();

                if (myData.HasRows)
                {
                    do
                    {

                        int id = myData.GetInt32("id");
                        string taskName = myData.GetString("taskName").ToString();
                        string description = myData.GetString("description").ToString();
                        DateTime expirationDate;
                        if (!myData.IsDBNull(3)) { expirationDate = Convert.ToDateTime(myData.GetString("expirationDate").ToString()); }
                        else { expirationDate = DateTime.MaxValue; }

                        string assosiatedEmailAddress = myData.GetString("assosiatedEmailAddress").ToString();
                        int assosiatedProjectId = myData.GetInt32("assosiatedProjectId");

                        Tasks instance = new Tasks();
                        instance._id = id;
                        instance._taskName = taskName;
                        instance._description = description;
                        instance._expirationDate = expirationDate;
                        instance._assosiatedEmailAddress = assosiatedEmailAddress;
                        instance._assosiatedProjectId = assosiatedProjectId;

                        list.Add(instance);

                    } while (myData.Read());
                }

                myData.Close();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }

            return list;
        }

        public List<Projects> SelectProjectsWhere(string where)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
            MySql.Data.MySqlClient.MySqlDataReader myData;
            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            List<Projects> list = new List<Projects>();
            string commandQuery = "Select id, projectTitle, description, expirationDate, assosiatedEmailAddress FROM Projects WHERE "
                                    + where + ";";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = commandQuery;

                myData = cmd.ExecuteReader();

                myData.Read();

                if (myData.HasRows)
                {
                    do
                    {

                        int id = myData.GetInt32("id");
                        string projectTitle = myData.GetString("projectTitle").ToString();
                        string description = myData.GetString("description").ToString();
                        DateTime expirationDate;
                        if (!myData.IsDBNull(3)) { expirationDate = Convert.ToDateTime(myData.GetString("expirationDate").ToString()); }
                        else { expirationDate = DateTime.MaxValue; }

                        string assosiatedEmailAddress = myData.GetString("assosiatedEmailAddress").ToString();

                        Projects instance = new Projects();
                        instance._id = id;
                        instance._projectTitle = projectTitle;
                        instance._description = description;
                        instance._expirationDate = expirationDate;
                        instance._assosiatedEmailAddress = assosiatedEmailAddress;

                        list.Add(instance);

                    } while (myData.Read());
                }

                myData.Close();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }

            return list;

        }

        public void DeleteProjectAndItsTasksWhereId(int Id)
        {
            string deleteQuery = "DELETE FROM Projects WHERE id = " + Id + ";";
            string deleteTaskQuery = "DELETE FROM TASKS WHERE assosiatedProjectId = " + Id + ";";

            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = deleteQuery;
                cmd.ExecuteNonQuery();
                cmd.CommandText = deleteTaskQuery;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }
        }

        public void DeleteProjectUpdateItsTasksWhereId(int Id)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";
            string deleteQuery = "DELETE FROM Projects WHERE id = " + Id + ";";
            string updateQuery = "UPDATE Tasks SET assosiatedProjectId = 1 WHERE assosiatedProjectId = " + Id + ";";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = deleteQuery;
                cmd.ExecuteNonQuery();
                cmd.CommandText = updateQuery;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }

        }

        public void DeleteTaskWhere(int Id)
        {
            MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();

            string connectionString = "server=localhost;User Id=root;Password=root;Persist Security Info=True;database=todo_db";

            string deleteQuery = "DELETE FROM Tasks WHERE id = " + Id + ";";

            conn.ConnectionString = connectionString;

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = deleteQuery;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Console.WriteLine("Error " + ex.Number + " has occurred: " + ex.Message);
            }
        }

    }

    public class Users
    {
        public string usernameField { get; set; }

        public string passwordField { get; set; }

        public string emailField { get; set; }
    }

    public class Projects
    {
        public int _id { get; set; }
        public string _projectTitle { get; set; }
        public string _description { get; set; }
        public string _comment { get; set; }
        public DateTime _expirationDate { get; set; }
        public List<Tasks> _tasks = new List<Tasks>();
        public string _assosiatedEmailAddress { get; set; }
    }

    public class Tasks
    {
        public int _id { get; set; }
        public string _taskName { get; set; }
        public string _description { get; set; }
        public string _comment { get; set; }
        public DateTime _expirationDate { get; set; }
        public string _assosiatedEmailAddress { get; set; }
        public int _assosiatedProjectId { get; set; }
    }

}

I've set everythig public, changed the getters and setters, removed the constructors but still i get the error that:
There was an error downloading the metadata from the address. Please verify that you entered a valid address.

the details say:
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: The type 'TODO.Web.TODO_db_Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.]
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +51902
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1440
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/TODO_db_Service.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'TODO.Web.TODO_db_Service', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +679246
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234
   System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +24
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
What is the problem?
Bechir Bejaoui
posted  1449 posts
since  Dec 06, 2007 
from 

 Re: Cannot add Service as ServiceReference in Silverlight Project
  Posted on: 09 Sep 2010        0  

Have you ever tested the wcf service address using the WCFTESTCLIENT
http://msdn.microsoft.com/en-us/library/bb552364.aspx
Every one among us was a beginner once.
http://dotnetuniver.blogspot.com/
       
Nevron Gauge for SharePoint
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved