vendredi 8 mai 2015

Storing WCF rest request data with SQL Server stored procedure

I have a simple interface in my WCF service with one method which gets a myRequest parameter

public interface IService
{
    [OperationContract]
    string MyOperation(myRequest request);
}

When I'm posting the data from the client, the content type is application/json, so the request body auto deserialise into myRequest object.

myRequest is a WCF DataContract:

[DataContract]
public class myRequest
{
    string id;
    string name;
    List<Phone> phones

    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string ID { get; set; }
    [DataMember]
    public List<Phone> Phones { get; set; }
}

and the Phone class

public class Phone
{
    public string Number { get; set; }
    public string Type { get; set; }

    public override string ToString()
    {
        return "[" + Number + "," + Type + "]";
    }
}

Ok, so now I would like to store the request data into my local SQL Server database and for that I need to use stored procedures. I want to send the myRequest object to SQL Server and let it deal with insert/update (I think what I will have to keep 2 tables: people and phones).

I don't have to much background about stored procedures but I will great to get from you guys the right approach to solve this.

Thanks.

Aucun commentaire:

Enregistrer un commentaire