-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: NullableTypes over Web Services
PostPosted: Tue Oct 04, 2005 9:43 am 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
I am looking for a solution to store NULL values in my entities. I came across the NullableTypes library by looking at this formum's postings. I do have a quick question before I jump into using them. Has anybody tried to send these values over a Web Service? Does that work as smoothly as the .NET value types, i.e. do the values get serialized / deserialized on both client and server end without any hassles?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 11:23 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
AFAIK, it should work perfectly well :)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 12:23 am 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
OK, I tried using NullDateTime in a Web Service, but the WSDL that is generated looks like this:

Code:
<s:complexType name="Trade">
  <s:sequence>
    <s:element minOccurs="1" maxOccurs="1" name="Id" type="s:long" />
    <s:element minOccurs="1" maxOccurs="1" name="ExpirationTime" type="tns:NullableDateTime" />
  </s:sequence>
</s:complexType>

<s:complexType name="NullableDateTime" />


Note the definition for NullableDateTime contains an empty implementation. What am I doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 3:52 pm 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
I believe the Nullable Types need to have some attributes on the properties to make sure it is serialized correctly. I'm testing it now.

There is going to be an issue with compatibility with other languages that consume the web service if you want to keep it completely standard.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 10:48 am 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
OK, it is the fact that all of the properties are read-only that it doesn't work.

Making the properties writable will change the way the Nullables work too much, so I am going to try implementing IXmlSerializable on the unllable types to handle it.

The other trick is getting it to use the Nullables library on the client side and not some automatically generated class with public fields. I'm looking into that also.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 1:36 pm 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
I've been playing with XmlSerializable and came up with this to make it show up in the wsdl:

This is in NullableInt32:
Code:
      #region IXmlSerializable Members

      public void WriteXml(System.Xml.XmlWriter writer)
      {
         writer.WriteElementString("HasValue", hasValue.ToString());
         if (hasValue)
            writer.WriteElementString("Value", _value.ToString());
      }

      public System.Xml.Schema.XmlSchema GetSchema()
      {
         XmlSchema s = new XmlSchema();

         s.Id = "nullables-int32"; //i don't know what this does, but an Id is required.

         XmlSchemaElement hasValueElement = new XmlSchemaElement();
         hasValueElement.Name = "HasValue";
         hasValueElement.SchemaTypeName = new XmlQualifiedName("boolean", "http://www.w3.org/2001/XMLSchema");
         hasValueElement.MinOccurs = 1;
         hasValueElement.MaxOccurs = 1;
         s.Items.Add(hasValueElement);

         XmlSchemaElement valueElement = new XmlSchemaElement();
         valueElement.Name = "Value";
         valueElement.SchemaTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
         valueElement.MinOccurs = 0;
         valueElement.MaxOccurs = 1;
         s.Items.Add(valueElement);
         
         return s;
      }

      public void ReadXml(System.Xml.XmlReader reader)
      {
         // TODO:  Add NullableInt32.ReadXml implementation
      }

      #endregion


Unfortunately this will still create some new dummy NullableInt32 on the client side. I'm working on causing it to deserialize to the existing NullableInt32.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.