Why does WCF sometimes add “Field” to end of generated proxy types?

前端 未结 5 2120
夕颜
夕颜 2021-02-04 05:11

Basically, I have a server-side type \"Foo\" with members X and Y. Whenever I use Visual Studio\'s \"Add Server Reference\" then I see the WSDL and the generated proxy both appe

相关标签:
5条回答
  • 2021-02-04 05:39

    Adding XmlSerializerFormat worked for me. Got solution from http://geekswithblogs.net/mipsen/archive/2010/02/06/field-postfix-in-wcf-reference.aspx

    [ServiceContract(Namespace="http://somenamespace.com/contracts")]    
    public interface ISchemaService
    {
        [OperationContract]
        [XmlSerializerFormat]
        void DoSomething(GeneratedType data);
    }
    
    0 讨论(0)
  • 2021-02-04 05:42

    I had the same issue, and sergiosp's answer got me headed in the right direction. Just adding some additional info to hopefully help someone else.

    Adding [System.ServiceModel.XmlSerializerFormatAttribute()] to the interface, and re-generating the client code resolved the problem for me.

    public interface IMyService
    {
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        [System.ServiceModel.OperationContract]
        recordResponse GetRecord(recordRequest request);
    
    }
    
    0 讨论(0)
  • 2021-02-04 05:43

    I had the same problem but i was able to find solution.

    In the interface if you add [DataContractFormat] tag you will end up with "XFieldField" case. But if you replace it with [XmlSerializerFormat] in the interface it will not change the names in the proxy generated.

    0 讨论(0)
  • 2021-02-04 05:43

    I had this problem too, but from the client I was still getting Field at the end of the class members even after making the mentioned change at the interface.

    The problem was, I was using a DataContractSerializer to work with disk file serialized requests (during the test of our service, we were getting serialized requests from the provider, to be able to debug before going live).

    After changing the DataContractSerializer to a XmlSerializer, specifying on its constructor the root element (by a typeof() call) and the rootnamespace (because by default, XmlSerializers write the standard namespace), I could deserialize the requests and work perfectly with the WCF Service.

    Hope this helps somebody. I lost soooo many time with this "issue".

    0 讨论(0)
  • 2021-02-04 05:45

    Typically, the generated proxy will have "XField" and "YField" as internal/protected/private fields, and expose the values through properties called "X" and "Y". There are options you can set when creating the proxy client to tweak that to your liking, I think.

    UPDATE: I don't seem to find any switches or options to control this behavior. It might depend on which serializer (DataContractSerializer vs. XmlSerializer) WCF uses for creating the client proxy.

    In the end, it's really more or less just an issue of coding style - functionally, it shouldn't make a difference.

    Marc

    0 讨论(0)
提交回复
热议问题