简体   繁体   中英

null value return from WCF service operation

I have a WCF service with an operation contract that returns null values. That is: it's supposed to return some custom class 'ProgressReport', but in the client application it shows up as null. In the WCF service itself the custom class is instantiated and returned without errors and without becoming null at any time.

The 'ProgressReport' class is not defined as DataContract because it is defined in another assembly.

For the operation that returns 'ProgressReport', the WcfTestClient informs me that it cannot perform operation because it uses type 'ProgressReport'. I've tried adding an operationcontract with System.Object as return type, but it gives me the same error (cannot perform operation because it uses type 'System.Object')

Does anyone know how to solve this?

You could try to extend the ProgressReport -class (if it's not sealed) and define that as a DataContract (but I think that does not help with the properties of the class as they needed to be marked as DataMembers ) or create a own class as a kind of a proxy and return this object:

[DataContract]
public class ProgressReportWcf : ProgressReport
{
}

or

[DataContract]
public class ProgressReportWcf
{
    [DataMember]
    public int Id { get; set; }
    //aso...

    public ProgressReportWcf(ProgressReport report)
    {
        Id = report.Id;
        //aso...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM