{"id":48,"date":"2004-11-17T10:53:16","date_gmt":"2004-11-17T10:53:16","guid":{"rendered":"http:\/\/www.pleus.net\/blog\/?p=48"},"modified":"2010-08-13T00:11:34","modified_gmt":"2010-08-12T22:11:34","slug":"interoperable-web-services-and-null-values-2","status":"publish","type":"post","link":"https:\/\/www.pleus.net\/blog\/?p=48","title":{"rendered":"Interoperable Web Services and Null Values"},"content":{"rendered":"<p>The meaning of a null is &#8220;value not set&#8221;. Apparently it is a difference whether you say the credit limit is zero or not set. Therefore sometimes it is necessary to convey null values over Web Services.<br \/>\nLuckily Web Services provide the means to express null values.<br \/>\nAssume the following Web Service method:<br \/>\n<font face=\"courier\"><br \/>\npublic String getName()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return null;<br \/>\n}<br \/>\n<\/font><br \/>\nThe reponse in the SOAP Message uses the <b>xsi:nil=&#8221;true&#8221;<\/b> to express the null value on the wire.<\/p>\n<p>This is fine as long as we use certain types as e.g. strings.<br \/>\nBut if we use types which have a different representation on different plattform we might run into problems. Even though they are represented by a legal XML Schema type.<br \/>\nFor instance the java types <b>java.util.Date<\/b> and <b>java.util.Calendar<\/b> are reference types on the Java platform.<br \/>\nThe equivalent type <b>System.DateTime<\/b> is a value type on the .NET plattform which can&#8217;t be null.<br \/>\nIf a reference type set to null is returned from a Java Web Service it causes a <b>System.FormatException<\/b> on the .NET plattform.<br \/>\nAs the SOAP reponse is valid it seems to be a bug in the .NET implementation. <\/p>\n<p>To avoid the problem wrap the reference type in an complex type as follows:<\/p>\n<p><font face=\"courier\"><br \/>\npublic class ServiceCalendar<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;public ServiceCalendar(Calendar date)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.date=date;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;public Calendar date;<br \/>\n}<\/p>\n<p>public class Service<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;java.util.Calendar cal= new GregorianCalendar();<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;public ServiceCalendar getDate()<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new ServiceCalendar(cal); \/\/ or return null;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>\n}<br \/>\n<\/font><\/p>\n<p>Enjoy<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The meaning of a null is &#8220;value not set&#8221;. Apparently it is a difference whether you say the credit limit is zero or not set. Therefore sometimes it is necessary to convey null values over Web Services. Luckily Web Services provide the means to express null values. Assume the following Web Service method: public String &hellip; <a href=\"https:\/\/www.pleus.net\/blog\/?p=48\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Interoperable Web Services and Null Values<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-soa","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":2,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions\/335"}],"wp:attachment":[{"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pleus.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}