Error while passing the DataContract object from client to Server ......
-
06 Maret 2012 15:36
Defined COntracts:==========================================================================
[ServiceContract]
public interface IService1
{
[OperationContract]
bool Create(String tableName);
[OperationContract]
bool Insert(DataModel row);
[OperationContract]
bool Delete(DataModel row);
[OperationContract]
bool Update(DataModel row);
}
[DataContract ]
[DataServiceKey ("PartitionKey","RowKey")]
public class DataModel// : TableServiceEntity
{
// TableServiceEntity Ent = new TableServiceEntity();
[DataMember]
public String DN{get;set;}
[DataMember]
public String Data{get;set;}
[DataMember]
public String PartitionKey { get; set; }
[DataMember]
public String RowKey { get; set; }
}=============================================================================
SERVER SERVICE:
public class TableService : IService1
{
public String tableName;
public TableServiceContext context;
public bool Create(String tableName)
{
this.tableName = tableName;
string accountname = "devstoreaccount1";
string accountkey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
string tableServiceAddress = "http://127.0.0.1:10002/devstoreaccount1";
var credentials = new StorageCredentialsAccountAndKey(accountname, accountkey);
var account = new CloudStorageAccount(credentials, false);
var tableAcc = new CloudTableClient(tableServiceAddress, credentials);
context = new TableServiceContext(tableServiceAddress, credentials);
return tableAcc.CreateTableIfNotExist(tableName);
}
public bool Insert(DataModel row)
{
context.AddObject(tableName, row);// I am getting error here as row object is empty ie NullValueReference
context.SaveChangesWithRetries();
return true;
}
.........//other func}
==============================================================================
CLIENT CODE: (WEB App with form interface)
public partial class _Default : System.Web.UI.Page
{
Service1Client s;
protected void Page_Load(object sender, EventArgs e)
{
s= new Service1Client();
}
protected void Button1_Click(object sender, EventArgs e)
{
bool handle=s.Create(tableName.Text.ToString());
response.Text = handle.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
DataModel row = new DataModel();
row.PartitionKey = pKey.Text.ToString();
row.RowKey = rKey.Text.ToString();
row.DN = dn.Text.ToString();
row.Data = data.Text.ToString();
//response.Text = row.ToString();
bool handle=s.Insert(row);
// response.Text = handle.ToString();
}
}========================================================
A.Navarajan
Semua Balasan
-
06 Maret 2012 15:40
I am getting the error in server side while calling the Insert function....it says row ie object of Datamodel is empty ... it asking me to use new... I dont know why i am getting the error...
In the client side i am storing all the value in the Datamodel object and passing it to server...And the server is says its empy...
I think there is some error while serializing... But i dont get it...Somebody help me...
A.Navarajan
-
06 Maret 2012 16:05
Hi Navarajan,
This seems to be a WCF issue. I think at the moment you call the Insert method the TableServiceContext is null. The WCF instance mode is per call (http://msdn.microsoft.com/en-us/magazine/cc163590.aspx). This means, each time you call the service a new instance of that class is created server side. Meaning, when you call the Insert method, it's as if you never executed the Create method (for that request). What I advise you to do is to call the Create method in your Insert method and this should solve your issue.
Sandrino
- Disarankan sebagai Jawaban oleh Sandrino Di Mattia 06 Maret 2012 16:05
- Ditandai sebagai Jawaban oleh Navarajan A 06 Maret 2012 16:53
-
06 Maret 2012 16:54
Yes Sandrino,
You are absolutely right...It solved the problem...thanks for your immediate reply...
A.Navarajan