How to change the behavior of string objects in web service calls via Windows Communication Foundati

Posted by Geri Langlois on Stack Overflow See other posts from Stack Overflow or by Geri Langlois
Published on 2010-06-04T20:01:21Z Indexed on 2010/06/05 14:02 UTC
Read the original article Hit count: 257

Filed under:
|

I have third party api's which require string values to be submitted as empty strings. On an asp.net page I can use this code (abbreviated here) and it works fine:

public class Customer
{
    private string addr1 = "";
    public string Addr1
    {
        get {return addr1;}
        set {addr1 = value;}
    }

    private string addr2 = "";
    public string Addr2
    {
        get {return addr2;}
        set {addr2 = value;}
    }

    private string city = "";
    public string City
    {
        get {return city;}
        set {city = value;}

    }
}

Customer cust = new Customer();
cust.Addr1 = "1 Main St.";
cust.City = "Hartford";
int custno = CustomerController.InsertCustomer(cust);

The Addr2 field, which was not initialized is still an empty string when inserted.

However, using the same code but called it through a web service based on Windows Communication Foundation the Addr2 field is null. Is there a way (or setting) where all string fields, even if uninitialized, would return an empty string (unless, of course, a value was set).

© Stack Overflow or respective owner

Related posts about wcf

Related posts about serialization