none
DataContractResolver ignored in Universal App RRS feed

  • Question

  • Hello,

    I have a WCF service that should be consumed by a WCF client defined in a portable class library. The class library contains the ServiceReference for the service. A helper class initializes the client and let you work with it.

    internal static CoreClient.CoreServiceClient GetCoreServiceClient(string protocol = null, string webserver = null, string vdir = null)
        {
            if (protocol == null)
                protocol = ServerConnection.Protocol;
            if (webserver == null)
                webserver = ServerConnection.WebServer;
            if (vdir == null)
                vdir = ServerConnection.VDir;
    
            var url = string.Format("{0}{1}/{2}/Core/CoreService.svc", protocol, webserver, vdir);
    
            var client = new CoreClient.CoreServiceClient(CoreService_Binding, new EndpointAddress(url));            
    
            foreach (OperationDescription operation in client.Endpoint.Contract.Operations)
            {                
                foreach(var behavior in operation.OperationBehaviors.OfType<DataContractSerializerOperationBehavior>())
                    behavior.DataContractResolver = new Helper.CoreContractResolver(myAssembly);
            }
    
            return client;
        }

    For each operation of the service a DataContractResolver is defined. The resolver defines, that all the types in an assembly are recognized as known types.

    This works fine when calling the client.DoSomething() (Where the return type is a custom type defined in the assembly) from a console application. I can set a breakpoint in the ContractResolver and debug it. But when calling it from an blank Universal Windows App the breakpoint is never reached.

    This results in a

    System.Runtime.Serialization.SerializationException: Error in line 1 position 327. Element 'http://tempuri.org/:LoadObjectResult' contains data of the 'foo.DummyData:Customer' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Customer' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.

    Does anyone has an idea why the ContractResolver is used when consuming the service from a console application and not in an Universal Windows App?

    Kind regards

    Tuesday, January 12, 2016 1:22 PM

All replies

  • Hi sTumPf84,

    According to this case, as you said you can call the WCF service from console application

    successfully. That means your WCF service is correctly. When you call the service from

    UWP, it throw a exception. So, could you share a test project about this case for help us

    to reproduce this issue. But, as far as I know, the .NET for UWP apps does not include

    all the members of each type. For information about individual types, see the linked

    topics. The documentation for a type indicates which members are included in the

    .NET for UWP apps.

    And, I thought this issue is relate to the UWP too. You can post this question to UWP

    forum also.

    Best Regards,

    Wanjun Dong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.



    Wednesday, January 13, 2016 8:59 AM
    Moderator
  • Hello Mr. Dong,

    how can I share a project?

    There is no option to attach anything.

    The last time I posted something I was not even allowed to post a link.

    Kind regards

    Wednesday, January 13, 2016 11:23 AM
  • Wow, after 5 days not a single response to where I can upload a sample project.

    This is a really stunning support.

    By the way, the link in your signature to participate the survey does not work (in fact it is no link).

    Tuesday, January 19, 2016 5:04 PM
  • Hi sTum,

    You can transfer the test project with oneDrive, then paste the URL here.

    I can copy the URL in my browser, and download it.

    Best Regards,

    Wanjun Dong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Wednesday, January 20, 2016 1:13 AM
    Moderator
  • Hello Mr. Dong,

    here is the link to the sample.

    https://onedrive.live.com/redir?resid=ED28BD2399011A28!1351&authkey=!ACT1n2ElMH-Le_8&ithint=file%2czip

    When running the Client.Data.Core.Test console application all three GetData calls work.

    When running the Client.Data.Core.UWPTest application the GetDataAsObject call stops with the SerializationException.

    The ContractResolver is never used by the UWP client.

    Kind regards


    Wednesday, January 20, 2016 12:37 PM
  • I guess that related to the UWP issue. You can post this question this thread to uwp forum.



    • Edited by Jimyken Monday, January 25, 2016 4:47 AM
    Monday, January 25, 2016 4:40 AM