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 append the word "Field" to all the members and change the casing of the first letter. IE, "X" and "Y" are renamed "xField" and "yField". Any idea why this is happening? I can't figure out the pattern.
Details -- I have a legacy ASMX web service which exposes a "Foo" type. I created a new WCF service that's a wrapper around that old web service -- the new service just wraps those methods and maybe updates the values of a few fields, but it exposes the exact same methods and returns the exact same types. I've tried re-creating the referenes several times, and every time, it always renames my fields: the varible "STUFF" is exposed in the wsdl and proxy as "sTUFFField". Variable "X" is exposed as "xField", etc.
Funny thing is I can't figure out the pattern -- I tried creating a new ASMX web service as a test and wrapping that -- variables are not renamed then. So I can't figure out the pattern of why/when WCF renames variables.
Anybody know?
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.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
Adding XmlSerializerFormat worked for me. Got solution from http://geekswithblogs.net/mipsen/archive/2010/02/06/field-postfix-in-wcf-reference.aspx
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.
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 aXmlSerializer
, specifying on its constructor the root element (by atypeof()
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".