Why are the fields with the optional "Specified" field always zero?

I have an application. Here I create customer service from WSDL. Some features are currently working fine. But some are wrong.

This is part of WSDL.

<xs:complexType name="TStartInfoCalcZoneViewForArea"> <xs:sequence> <xs:element minOccurs="0" name="ID" type="xs:int"/> <xs:element minOccurs="0" name="startFreq" type="xs:double"/> <xs:element minOccurs="0" name="endFreq" type="xs:double"/> <xs:element minOccurs="0" name="startTime" type="xs:string"/> 

This is part in C #

 public partial class TStartInfoCalcZoneViewForArea { private int idField; private bool idFieldSpecified; private double startFreqField; private bool startFreqFieldSpecified; private double endFreqField; private bool endFreqFieldSpecified; /// <remarks/> [System.Xml.Serialization.XmlElementAttribute(Order=0)] public int ID { get { return this.idField; } set { this.idField = value; } } /// <remarks/> [System.Xml.Serialization.XmlIgnoreAttribute()] public bool IDSpecified { get { return this.idFieldSpecified; } set { this.idFieldSpecified = value; } } 

I set the value for these fields. for instance

 .ID = 100; .IDSpecified = true; // I set nothing, false. But result is same. 

The problem is that all of these fields (ID, endFreq, startFreq) are null in the gsoap server.

What is the cause of this problem? How can i fix this?

Update - reason and solution

The problem was: I do not have the source code for the "gsoap server". But by agreement in our company we use (can watch) the magazine from this application. This log was incorrect (firstly, there are no log messages in this situation. Then this message was incorrect. After fixing the problem, it was resolved).

There are also many classes and structures with the "double" field. Therefore, in some classes, I set "... Specified = true;". In other cases, I do not set "... Specified = true;". After the log has been fixed, I see a problem.

So I need to set "... Specified = true;" in all classes. I don’t know if this decision is right because

1) I ask other programmers in our company, but they do not know the normal wcf.

2) set "... Specified = true;", but I see the same message in the log.

+6
source share
1 answer

The problem is this: the idField field is of type int , so in .NET it cannot be zero - it must always have a real integer value, for example. 0.

An XML schema, on the other hand, defines this as optional:

 <xs:element minOccurs="0" name="ID" type="xs:int"/> 

Thus, the .NET client cannot find out if this value 0 in your idField that there is no specific value (since it has minOccurs=0 ), or you really want to send the value 0 to the server.

What idFieldSpecified comes into play:

  • if idField is 0 and idFieldSpecified is false β†’ then no value is defined (e.g. SQL NULL bit)

  • if idField is 0 and idFieldSpecified is true -> then you really want to send the value 0 caller

So, if you have fields with an accompanying field (field)Specified , if you want to really send the value, then you must set the value of (field)Specified to true - otherwise the value is set to NOT .

+9
source

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


All Articles