2

I have a WebService written in VB.NET, in it, I have a Long defined as such:

<s:element minOccurs="0" maxOccurs="1" name="clientId" type="s:long"/>

Now, whenever I call this WS from another VB.NET application, along with settings clientId var, I also have to set clientIdSpecified to True - thats the quirk of .NET. However, my client works with Java, and the question is - do they have to do the same and set clientIdSpecified to True?

This boolean is not part of the specs so if they do need to set it up, I have to warn them.

George
  • 2,165
  • 2
  • 22
  • 34
  • Yes, that is not helpful, isn't it? ;).... I'll remove and update the comment. – Petru Gardea Oct 22 '12 at 21:40
  • It really depends on what XSD-to-code binding technology your Java friends are using. And even within that technology, it depends on version. E.g.: JAXB 1.x vs. 2.x, custom settings vs. default bindings; for a sample discussion, take a look at [this](http://stackoverflow.com/questions/12860742/jaxb-bean-generation) – Petru Gardea Oct 22 '12 at 21:41

2 Answers2

2

if your client is using java, just give them the xsd file and it should be good enough because it can be compiled into java classes that provide validation before being marshaled into xml.

Things to note though, minOccurs=0 means it is optional to set.

Wins
  • 3,420
  • 4
  • 36
  • 70
  • I will provide the XSD to the client, but the question is, do they have to set the `clientIdSpecified` variable to `True` in order to pass `clientId` value? Because thats what I have to do in .NET. I don't know if thats a quirk of VB.NET or it affects Java too. – George Oct 22 '12 at 17:13
  • As far as I remember, no. Is the clientId a mandatory property? – Wins Oct 22 '12 at 17:18
  • `clientId` is not mandatory, hence the `minOccurs=0`. However, when I DO want to pass a non-null value in `clientId` and I am using a VB.NET application to do it, I have to set `clientIdSpecified=True` - this is a .NET quirk. My concern is whether someone using a Java application to call my WS will need to do the same or not. the `clientidSpecified` does not appear in the XSD, it appears in the Reference.vb file in the visual Studio when I add WebService to the project. – George Oct 22 '12 at 19:32
  • 1
    If the java side is using JAX-WS then no, the schema compiler will represent the element as a `java.lang.Long` which they can set to `null` or not null as required. But all you need to care about is getting the WSDL right, how the client toolkit interprets that WSDL is up to them. – Ian Roberts Oct 22 '12 at 21:36
  • 1
    If I recall correctly, the java side will be represented by java.lang.Long, hence once it's set, it's not null. – Wins Oct 22 '12 at 23:27
  • So, if I understand this correctly - a Java Long can be null. Right? Because in .NET, a Long cannot be null, unless declared as `Nullable (of Long)`. When it is declared as `Nullable` that .NET quirk kicks in. Looks like Java doesn't have that little quirk. Glad to hear it. Thanks folks! – George Oct 23 '12 at 13:46
  • Yes, java Long is automatically null able, but once it' set, it's not null anymore – Wins Oct 23 '12 at 14:35
  • _once it' set, it's not null anymore_ - do you mean once Long is set to a value you cannot set that Long back to null? – George Oct 23 '12 at 15:00
  • Of course you can set it back to null. When I said 'once it's set, it's not null anymore' means you don't need to explicitly say clientIdSpecified=true unless if the XML schema has that property specified. – Wins Oct 24 '12 at 00:08
  • the funny part about .NET is that whether you supply a value in `clientId` or not, if you do not set `clientIdSpecified=true`, the client will not pass the `clientId` value to the server. So, if I am using .NET on the client side and I call server and I want to pass some non-null value to the server, I must set `clientIdSpecified` to `True`. Otherwise server receives nothing. – George Oct 24 '12 at 14:48
  • That's weird, but I'd be interested to hear from .NET expert if there is explanation behind that behavior.. – Wins Oct 24 '12 at 18:21
1

On the Java side this kind of construct would typically be compiled into a property of type java.lang.Long (the wrapper class) rather than long (the primitive type), using the null value to represent the case where the element is not present.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183