The data contract type "..." cannot be deserialized because the required data members RRS feed

  • Question

  • HI There,

                  In my Application, I have a WCF service. I am trying to send a Json Object and get the Json object as Response.

    But every time, I am getting error "The data contract type 'TestConsole.localhostrREF4.PrimeDataProperty' cannot be deserialized because the required data members  'isPrimeResultField, isPrimeResultFieldSpecified, isPrimeResultSpecified1Field, isPrimeResultSpecified1FieldSpecified, numberField, numberFieldSpecified, numberSpecifiedInField, numberSpecifiedInFieldSpecified' were not found.

    My Web Service name is "ISAJsonWebService"

    Here is my code of Web Service:


        public interface IJsonWebService
            [WebInvoke(UriTemplate = "/GetData",
                 Method = "POST",
                RequestFormat = WebMessageFormat.Json,
                ResponseFormat = WebMessageFormat.Json)]
            PrimeDataPropertyOut GetData(PrimeDataProperty value);
        public class PrimeDataProperty
            public int number { get; set; }
            public bool NumberSpecifiedIn { get; set; }
            public bool IsPrimeResult { get; set; }
            public bool IsPrimeResultSpecified { get; set; }
        public class PrimeDataPropertyOut
            public bool IsPrimeResultOut { get; set; }
            public bool IsPrimeResultSpecifiedOut { get; set; }

     EndPoint Code behind JsonWebService.svc.cs 

    public class JsonWebService : IJsonWebService
            public PrimeDataPropertyOut GetData(PrimeDataProperty value)
                return new PrimeDataPropertyOut
                    IsPrimeResultOut = true,
                    IsPrimeResultSpecifiedOut = true

    Here is my Web Config:

    <?xml version="1.0"?>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
        <compilation debug="true" targetFramework="4.7.1" />
        <httpRuntime targetFramework="4.7.1"/>
          <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
          <service behaviorConfiguration="serviceBehavior" name="ISAJsonWebService.JsonWebService">
            <endpoint address="" behaviorConfiguration="jsonEndpointBehavior"
              binding="webHttpBinding" name="json" contract="ISAJsonWebService.IJsonWebService">
                <dns value="localhost" />
            <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
            <endpoint address="wsHttpBinding" behaviorConfiguration="wsHttpBinding"
              binding="wsHttpBinding" bindingConfiguration="" name="wsHttpBinding"
                <dns value="localhost/wsHttpBinding" />
            <behavior name="jsonEndpointBehavior">
              <webHttp />
            <behavior name="wsHttpBinding" />
            <behavior name="serviceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
        <modules runAllManagedModulesForAllRequests="true"/>    
        <directoryBrowse enabled="true"/>

    I am trying to Consume the web service from a Console App.

    Here is the code:

    static void Main(string[] args)
                localhostrREF4.JsonWebService jsonWebServiceRef = new localhostrREF4.JsonWebService();
                PrimeDataProperty pdp = new PrimeDataProperty { number = 1, NumberSpecifiedIn = false, IsPrimeResult = false, IsPrimeResultSpecified = false };
                WebClient client = new WebClient();
                client.Headers["Content-type"] = "application/json";
                MemoryStream ms = new MemoryStream();
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(PrimeDataProperty));
                serializer.WriteObject(ms, pdp);
                byte[] data = client.UploadData("http://localhost:65256/JsonWebService.svc/GetData", "POST", ms.ToArray());
                Stream stream = new MemoryStream(data);
                var obj = new DataContractJsonSerializer(typeof(PrimeDataProperty));
                var returnPrimeDataProperty = obj.ReadObject(stream) as PrimeDataProperty;

    in the last line (Bold Text) is throwing exception.

    Please let me know, what I am missing.


    Saturday, May 5, 2018 6:54 PM

All replies

  • Hi mramin,

    I made a test, and I fail to reproduce your issue.

    Could you share us your test project directly?

    Even through, I did not receive any error, I think you should use “PrimeDataPropertyOut” instead of “PrimeDataProperty” since your service return “PrimeDataPropertyOut”.

                var obj = new DataContractJsonSerializer(typeof(PrimeDataPropertyOut));
                var returnPrimeDataProperty = obj.ReadObject(stream) as PrimeDataPropertyOut;

    Best Regards,

    Tao Zhou

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, May 7, 2018 1:42 AM