Unexpected error when inserting list in sharepoint

Thursday, July 3, 2014

I have created a WCF service and defined a function over there which access the sharepoint web service that access the Lists. Then, I have hosted WCF service in IIS. and I can access its URL successfully from other computer. Therefore, I have created windows form application and given service reference for the service. But when I run the application and access the function, it give the exception. When I used try catch block. I came to know that function is successfully being called. The error is when I am saving List in sharepoint. Kindly assist me.

Here is the Exception:

General Error - An error occurred while processing this request. - System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.HttpWebRequest.MakeMemoryStream(Stream stream) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at System.Data.Services.Client.DataServiceContext.SaveResult.BeginNextChange(Boolean replaceOnUpdate)

Here is my WCF service code:

public string Registration(string FirstName, string LastName, string UserName, string IdentityID, string IdentityExpiryDate, string Birthdate, string Password, string ConfirmPassword, string Gender, string MobileNo, string Phone, string Fax, string Email, string PreferredContact, string AccountType, string Nationality)
string error = "";
TrainingDataContext context = new TrainingDataContext(new Uri("http://abc:port/sites/_vti_bin/listdata.svc/"));
context.Credentials = CredentialCache.DefaultCredentials;

RegistrationItem item = new RegistrationItem();

item.FirstName = FirstName;
item.LastName = LastName;
item.UserName = UserName;
item.IdentityID = IdentityID;
item.IdentityExpiryDate = DateTime.Parse(IdentityExpiryDate);
item.Birthdate = DateTime.Parse(Birthdate);
item.Password = Password;
item.ConfirmPassword = ConfirmPassword;
item.GenderValue = Gender;
item.MobileNo = MobileNo;
item.Phone = Phone;
item.Fax = Fax;
item.Email = Email;
item.PreferedContactValue = PreferredContact;
item.AccountTypeValue = AccountType;
item.NationalityValue = Nationality;

catch (Exception ex)
error += "General Error - " + ex.Message + " - " + ex.InnerException.Message;

catch (Exception ex)
error += "Outside Error - " + ex.Message + "--" + ex.InnerException.Message;

return error != "" ? error : "DONE";

Here is my client side code:

Service1Client client = new APIService.Service1Client();

string result = client.Registration("abc",
"2012-11-16 10:00:00",
"1990-11-16 10:00:00",