Why does my wcf help system have extra arguments?

I am trying to convert an ASP.Net web service to a WCF application. The client is located on the .Net Compact Framework, which does not support WCF, so I need to make sure that WCF supports ASP web services. When I add a link to a web service in Visual Studio, the proxy class methods created have additional arguments.

For example, if a method is defined as:

public void GetEmpInfo(int empNo) 

This method will appear in the proxy class as:

 public void GetEmpInfo(int empNo, bool empNoSpecified) 

What causes it and how to stop it?

+4
source share
3 answers

Mark this blog post ...

Where do these additional logical “specified” members come from and what do they do? The answer is the scheme that the WCF data contract serializer is generated by default. Because of how the version control model works, serializer generates all data items as optional items. The old network service stack, ASP.NET Web Services ("ASMX"), uses another serializer, XmlSerializer, which supports full XML schema and fidelity. The XmlSerializer displays all the optional elements for two participants: one represents the data itself, and one indicates whether the data is actually - this is a member of "xxxSpecified". These xxxSpecified Elements must be set to true in order to serialize the corresponding "actual data" members.

+8
source

The .NET Compact Framework supports a subset of WCF. You can view this support on MSDN . See, it can support enough so that you can remove legacy web services support.

+1
source

This happens for types with a default value other than zero. In these cases, the web service cannot know whether the parameter was set to the default value or simply not set at all.

You can get rid of the additional specification parameter by decorating your operation with the [XmlSerializerFormat] attribute, for example:

  [OperationContract] [XmlSerializerFormat] string GetEmpInfo(int? empNo); 

This attribute can also be added at the class level, and this will make sense in most cases.

I understand that you can handle this situation using types with a null value ( int? ), But I could not fix it using this.

0
source

Source: https://habr.com/ru/post/1286241/


All Articles