tags:

views:

1091

answers:

1

We are using C#, ASP.NET & WCF. I am trying to send form data to a web service which in turn inserts/updates a database with the data from my form. How should I send over my data?

We have the forms populated fine but are having some issues with sending updates back to the web service. We have determined that it is not great practice to use datasets in this situation, it is slow and we have to do too many SELECT *'s for our liking.

I have about 15 fields that need to go across. One team member wants to pass everything as a parameter which I dont think is optimal. We tried sending everything across in an Object[] array but are receiving a weird error "Type 'System.DBNull' with data contract name 'DBNull:http...' is not expected. Add any types not known statically to the list of known types",

Any suggestions are most welcome.

+2  A: 

We use WCF to define our Data Contracts and Data Methods using attributes.

Basically we create an assembly to define all our classes and another assembly to provide the WCF connective bits

OPur class assembly contains a service class and several message classes.

We define an interface for our service and mark it up with relevant WCF markup. This is our Service Contract.

[ServiceContract]
public interface IExampleWebService
{
    [OperationContract]
    CreateAccountResponse CreateAccount(int parameter, CreateAccountArguments another parameter);

    [OperationContract]
    DeleteAccountResponse DeleteAccount(int parameter);
}

We implement this interface in a class and we create various data contracts (our response and argument classes).

[DataContract]
public class CreateAccountResponse
{
    [DataMember]
    public bool CreatedOk { get; set; }

    [DataMember]
    public int AccountId { get; set; }
}

These classes are exposed to our form using the Web Service (We create another assembly as a web service and have a class that inherits from our Service Class (not shown in this example) so we let Visual Studio do all the work setting up the WCF service as we reap the benefits with an easy to use and maintain Web Service.

Brody