如何在WCF实现的aspx页面中解决此错误? [英] How to resolve this error in WCF implemented aspx page?

查看:83
本文介绍了如何在WCF实现的aspx页面中解决此错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET中使用WCF进行注册提交。所有内容似乎都很好。但是当我运行时,输入详细信息并提交它不会在数据库中的表格内部显示详细信息。

IService1.cs

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

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



Service1.svc.cs

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


Default.aspx.cs

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;
    }
}

推荐答案

检查你的web.config文件。可能存在问题。
Check your web.config file. There may be an issue.


这篇关于如何在WCF实现的aspx页面中解决此错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆