I have Java Web service , and a parameter to one web method is a custom Java type
public class KeyList {
public Integer key;
public Integer[] nums ;
public Integer result;
}
The Web service updates the Result value and returns the KeyList object to the client.
I have a C# client to this Web service ( generated in Visual Studio by adding Service Reference and pointing to the wsdl url ). When I receive the keyList object in C# , the first part ( Integer key ) comes out as 0. If I change the Java custom type to use int key ( rather than Integer Key ) in the KeyList type , then it works fine for the C# client.
I wanted to see if the wsdl was drastically different between the two cases ( using int and Integer ) , but it turns out that the only difference is a minOccurs attribute.
when using Integer key
<xs:element name="key" type="xs:int" minOccurs="0" />
when using int key
<xs:element name="key" type="xs:int" />
What is the cause for the C# client not correctly receiving the updated Integer in the return value from the service ? Needless to say it works fine for a Java client either way.
Edit : C# class generated by VS for KeyList :
public class keyList : INotifyPropertyChanged{
private int keyField;
private bool keyFieldSpecified;
private int?[] numsField;
private PropertyChangedEventHandler PropertyChanged;
private int resultField;
private bool resultFieldSpecified;
public event PropertyChangedEventHandler PropertyChanged;
public keyList();
protected void RaisePropertyChanged(string propertyName);
[XmlElement(Form=XmlSchemaForm.Unqualified, Order=0)]
public int key { get; set; }
[XmlElement("nums", Form=XmlSchemaForm.Unqualified, IsNullable=true, Order=1)]
public int?[] nums { get; set; }
[XmlElement(Form=XmlSchemaForm.Unqualified, Order=2)]
public int result { get; set; }
[XmlIgnore]
public bool resultSpecified { get; set; }
}
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
Integer in java can be null that is why you see minOccurs="0"
. int can not be null and this is why minOccurs is missing. In C# int (or Int32 which is the same) can not be null so it does not expect minOccurs="0"
. The problem is most likely in Visual Studio proxy generator.
It should have generated nullable int in C# (Int32?
or int?
or Nullable<Int32>
) for this element:
<xs:element name="key" type="xs:int" minOccurs="0" />
Depending on how you generated this proxy, Visual Studio might have added additional bool field called 'keySpecified'. It sometimes adds "Specified" suffix to the name of nullable field. It expects you to write code like this:
if(res.keySpecified){
// use res.Key
} else {
// assume res.Key is null
}
If 'keySpecified' has not been generated you can look at generating proxy with svcutil. It has a lot more options than what is exposed in Visual Studio. Another possible solution for you is to just stick with int on java side because it maps directly to int on C# side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With