WCF: Best Practice for Submitting Form Data to a Web Service?

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

We have completed forms but are having trouble pushing updates back to the web service. We determined that there is not much practice in this situation to use datasets, it is a slow process, and we need to do too many SELECT * to our liking.

I have about 15 fields to go through. One team member wants to pass everything as a parameter, which I think is not optimal. We tried to send everything to an Object [] array, but got a strange "Type" System.DBNull error with the data contract name "DBNull: http ..." not expected. Add any types not statically known to the list of known types ",

Any suggestions are greatly appreciated.

0


source to share


1 answer


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 WCF connecting bits

The OPUR class node contains a service class and several message classes.

We define an interface for our service and mark it with the appropriate 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 will implement this interface in a class and 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 in our form using a 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 customizations as needed take advantage of WCF with an easy-to-use and maintainable web service.

+2


source







All Articles