only string data is saved from WCF service when using Web Reference instead of Service Reference in VS 2008

Posted on 2011-04-27
Last Modified: 2012-06-27
I have created a WCF webservice that accepts a collection of an object of made of simple datatypes (int, string datettime)

when i test the service from the client side (a mobile application created in VS2008)  using and add a Service Reference, all the data is saved to the database, however if I add a Web Reference, only datatypes of type string are saved. Also no exception is generated.

I am using basicHTTPBinding in the webservice to make it compatible with older client applications.

I cannot use a service reference at the client side because i need to implement a mobile solution on the compact framework 3.5 which is not supported.

Any help please?
Question by:emcict

    Accepted Solution


    I found the solution on a Blog  article titled:
    Solving the "disappearing data" issue when using Add Web Reference or Wsdl.exe with WCF services

    in short you need to add the attribute  [DataMember(IsRequired=true)] on each Class Property because the default WCF serializer generates all data members as optional elements.

    public partial class MeterReadingResult
            [DataMember(IsRequired = true)]
            public DateTime? MeterReadingDateTime { get; set; }
            [DataMember(IsRequired = true)]
            public int MeterReadingResultValue { get; set; }
            public string UtilitiesDeviceType { get; set; }

    Open in new window

    LVL 25

    Expert Comment

    Use channel factory to create proxy instead of any references. Link has more details.

    Author Closing Comment

    it has worked for me and posted it so it might help others.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now