[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-04-27
Medium Priority
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
  • 2

Accepted Solution

emcict earned 0 total points
ID: 35481598

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

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

Author Closing Comment

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 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