Click here to Skip to main content
15,891,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I used WCF for registration submission in ASP.NET..everything seems to be pretty fine.But while i run ,enter details and submit it doesn't land details inside table at the database.
IService1.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService1
{
    
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string registrationdetails(userinfo obj);

    }


    [DataContract]
    public class userinfo
    {
        string First_Name = string.Empty;
        string Last_Name = string.Empty;
        string Password = string.Empty;
        string R_Password = string.Empty;
        string EMail_Id = string.Empty;
        string Country = string.Empty;

        [DataMember]
        public string F_Name
        {
            get { return First_Name ; }
            set { First_Name = value; }
        }

        [DataMember]
        public string L_Name
        {
            get { return Last_Name; }
            set { Last_Name = value; }
        }

        [DataMember]
        public string Pwd
        {
            get { return Password; }
            set { Password = value; }
        }

        [DataMember]
        public string R_Pwd
        {
            get { return R_Password; }
            set { R_Password = value; }
        }

        [DataMember]
        public string Email
        {
            get { return EMail_Id; }
            set { EMail_Id = value; }
        }

        [DataMember]
        public string Country_
        {
            get { return Country; }
            set { Country = value; }
        }
    }
}


Service1.svc.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;

namespace WcfService1
{
    public class Service1 : IService1
    {

        public string registrationdetails(userinfo obj)
        {
            string Message;
           
            SqlConnection con = new SqlConnection(@"Data Source=KAARTHICK-PC\KAARTHICKRAMAN;Initial Catalog=sample;Integrated Security=True");

            con.Open();
                SqlCommand cmd = new SqlCommand(" insert into Registration_Details(First_Name,Last_Name,_Password,Email_Id,Country) values(@First_Name,@Last_Name,@_Password,@Email_Id,@Country)", con);
                cmd.Parameters.AddWithValue("@First_Name", obj.F_Name);
                cmd.Parameters.AddWithValue("@Last_Name", obj.L_Name);
                cmd.Parameters.AddWithValue("@_Password", obj.Pwd);
                cmd.Parameters.AddWithValue("@Email_Id", obj.Email);
                cmd.Parameters.AddWithValue("@Country", obj.Country_);
                int result = cmd.ExecuteNonQuery();
                if (result == 1)
                {
                    Message = obj.F_Name + obj.L_Name + ",your details have been inserted successfully";
                }
                else
                {
                    Message = obj.F_Name + obj.L_Name + ",submission not successfull.TRY AGAIN!";
                }
                return Message;
                con.Close();
        }
    }
}

Default.aspx.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServiceReference1;

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

    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        ServiceReference1.Service1Client Objservice = new ServiceReference1.Service1Client();
        userinfo obj =new userinfo();
        obj.F_Name = TextBox1.Text;
        obj.L_Name = TextBox2.Text;
        obj.Pwd = TextBox3.Text;
        obj.Email = TextBox5.Text;
        obj.Country_ =TextBox6.Text;
        string result = Objservice.registrationdetails(obj);
        Label7.Text = result;
    }
}
Posted
Updated 12-Mar-15 5:29am
v4
Comments
Praveen Kumar Upadhyay 12-Mar-15 10:57am    
Do you get error message like "submission not successfull.TRY AGAIN!"?
Member 1097736 12-Mar-15 11:08am    
no,the debugger at VS2012 throws out this..pointing to string result = Objservice.registrationdetails(obj); in Default.aspx.cs

There was no endpoint listening at http://localhost:59276/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Oshtri Deka 13-Mar-15 5:26am    
Is service online? Can you reach it with your browser?

1 solution

Check your web.config file. There may be an issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900