• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • Last Modified:

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

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?
  • 2
1 Solution
emcictAuthor Commented:

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

Use channel factory to create proxy instead of any references. Link has more details.
emcictAuthor Commented:
it has worked for me and posted it so it might help others.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now