Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wcf

asmx

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?

like image 341
tavistmorph Avatar asked Jul 22 '09 12:07

tavistmorph


People also ask

What is the use of proxy class in WCF?

Actually Proxy is a class in WCF that is used to communicate with client application. We can simply get the entire configuration through the proxy class. There is no need to do extra effort to generate the configuration setting for the client. Proxy class used when you think that your service must be loosely coupled.

What is client proxy in WCF?

Proxy is an object in memory on the client-side that exposes the same Interface or API that the WCF service does. Your consuming code will make calls against that proxy and proxy will dispatch those calls as SOAP Messages to the WCF service.


1 Answers

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);

}
like image 80
tgriffin Avatar answered Oct 01 '22 08:10

tgriffin