我已经定义了一个服务合同,并且操作已经实施。这是我实现的服务的一个示例:我是否正确使用WCF服务从客户端接收数据并将其存储在数据库中?
public int CreateIncident(string incidentName, string location, DateTime timeStamp)
{
//Initilise db object to reference incidentDB database
incDBEntities db = new incDBEntities();
int incId = db.Incidents.Max(i => i.incId);
// Create new record with incremented incident id and assigned fields
Incident inc = Incident.CreateIncident(++incId);
inc.description = incidentName;
inc.location = location;
inc.whenReported = timeStamp;
//Add the incident instance and save changes/updates made to database
db.AddToIncidents(inc);
db.SaveChanges();
return inc.incId;
}
客户端使用数据作为参数来调用此服务。
是否确定的参数分配给数据字段和数据存储在数据库中? 目前,我已成功地通过WCF Test客户端本地发送数据并将其存储在数据库中。
我没有定义数据合同。所以我不确定当远程客户端通过Android或Microsoft应用程序拨打电话时该服务是否可以正常工作。
试着问一个更具体的问题。这非常含糊。 – 2012-01-05 21:26:17
好吧,我试着让它更具体。如果有人能提供一些答案/建议,我将不胜感激。 – Qwerty 2012-01-05 21:44:36
我想这是可以的,只要你为你的服务添加一些安全级别,这样你就不会不需要的插入到你的数据库中。 – TheBoyan 2012-01-05 21:47:47