dcsimg
Results 1 to 2 of 2

Thread: [RESOLVED] Is there a way to force inclusion of a data contract?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Resolved [RESOLVED] Is there a way to force inclusion of a data contract?

    I am using VS2012 and .NET 4.5 on Windows 7.

    I have a web service that has been working for quite some time. At issue is a specific data contract that is returned by only two Operation Contracts. For reasons of my own, I wanted to have them return a generic object that the GUI client could then cast into the appropriate type. Here's the data contract in question:

    Code:
        [DataContract]
        public class MeasureSummary
        {
            [DataMember]
            public int PQRSMeasureID { get; set; }
    
            [DataMember]
            public int? MeasureNumber { get; set; }
    
            [DataMember]
            public int ScenarioCount { get; set; }
    
            [DataMember]
            public int TotalDiagCodeCount { get; set; }
    
            [DataMember]
            public int TotalProcCodeCount { get; set; }
    
            [DataMember]
            public int TotalNumerCodeCount { get; set; }
    
            [DataMember]
            public int TotalCodeCount { get; set; }
        }
    
        [OperationContract]
        [FaultContract(typeof(MeasureFault))]
        MeasureSummary GetMeasureSummary(int MeasureID);
    
        [OperationContract]
        [FaultContract(typeof(MeasureFault))]
        MeasureSummary GetAllMeasuresSummary();

    All that worked fine. So I converted the first of the two operation contracts, and it worked fine. It returned the following datatype:

    Code:
        [OperationContract]
        [FaultContract(typeof(MeasureFault))]
        GenericReturnType GetMeasureSummary(int MeasureID);
    
        [DataContract]
        public class GenericReturnType
        {
            [DataMember]
            public ErrorDetails Error { get; set; }
    
            [DataMember]
            public Object ReturnData { get; set; }
        }
    In this return type, I store some very detailed information in ErrorDetails on where the service error occurred and what it was, above and beyond the standard Exception class. And ReturnData contains whatever data should be returned.

    As I said, this worked just fine... it got the requested data and the client cast the ReturnData object into the desired MeasureSummary data. Bingo. Concept validated and functioning properly.

    Then I converted the second as follows:

    Code:
            [OperationContract]
            [FaultContract(typeof(MeasureFault))]
            GenericReturnType GetAllMeasuresSummary();
    At this point, something very strange happened. The compiler started issuing errors when trying to compile the GUI client, saying that MeasureSummary wasn't a recognizable data type. After some thought, I built a dummy function as an operation contract that returned MeasureSummary, and then the client could see the data type again. I removed the dummy function from the interface, and got the error again. Added it back, and things worked like a charm.

    Code:
            [OperationContract]
            [FaultContract(typeof(MeasureFault))]
            MeasureSummary GetMSTest();
    So my conclusion is that the data contract wasn't built and released because no operation contract actually used the data type. And, since it isn't used, it doesn't even allow the client to know there is such a data type. Is there a way to force it to do so, anyway? For my purpose, I need the client to see the MeasureSummary datatype, regardless of whether or not it is specifically used by any operations.

    Any suggestions would be appreciated.
    Last edited by HongKongCV; Jun 8th, 2015 at 05:35 PM. Reason: Added additional information

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Re: Is there a way to force inclusion of a data contract?

    This is how it goes some days. I've been looking at this for two hours, and five minutes after I post this question, I tried something that worked like a charm. The key is to declare MeasureSummary as a known type for the service.

    Code:
    [ServiceContract, ServiceKnownType(typeof(MeasureSummary))]
    With that in place, things are working again. Sorry to bother you all, and have a good day.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width