cancel
Showing results for 
Search instead for 
Did you mean: 

Returning null values to a Web Service datawindow from .NET

Former Member
0 Kudos

Sorry everyone, I am working in a new area for me, web services, and I keep having to ask questions here. Hopefully I'll get the hang of it soon

I have a .NET web service returning SOAP data using basicHTTPBinding. I can create a datawindow from the method and retrieve data. One of the columns in the returned data is an int, and that column in the database for one of the records is set to null. However, int is not nullable in .NET. You can use int? to get a nullable version but that can't be passed back to Powerbuilder as it is a complex datatype apparently.

So my question is, how do you get null values from the database to a Powerbuilder datawindow via a .NET Web Service (or is it not possible and I should just give up).

Thank you!

Accepted Solutions (1)

Accepted Solutions (1)

CobyKako
Advisor
Advisor
0 Kudos

Hi Aron,

Please review this info from the documentation:

SyBooks Online

The System.Nullable type is a standard representation of optional values and as such it is also classified as generic and therefore cannot be consumed in PowerBuilder .NET applications.

In .NET Assembly and Web service targets, you can select a check box to map PowerBuilder standard datatypes to .NET nullable datatypes. Nullable datatypes are not Common Type System (CTS) compliant, but they can be used with .NET Generic classes if a component accepts or returns null arguments or if reference arguments are set to null

HTH,

Jacob

Former Member
0 Kudos

Thanks Jacob, the link is related to code in conditional compilation blocks, so it doesn't really help me with getting data into a Web Service datawindow, at least as far as I can tell. I didn't see any checkboxes to map Powerbuilder datatypes to .NET nullable datatypes, although it does sound like something I could use

Former Member
0 Kudos

Hi Aron;

  I think Jacob was talking about ....

Regards ... Chris

Former Member
0 Kudos

Thank Chris, but I believe that's in PB.NET when it is the Web Service provider (at least I can't see it in PB Classic anywhere) and I'm trying to call a C# WCF Web Service from PB Classic.

However as Bruce has said elsewhere perhaps I need a PB.NET app between my PB Classic and the C# WCF Web Service.

I was hoping PB Classic could be used to retrieve data straight into a datawindow from a C# WCF Web Service, but it seems that it can't as there are too many limitations (SOAP, XML serialization, no null values, I can live with the others but not being able to return null values is a big limitation).

Former Member
0 Kudos

FYI ... In any WS DWO, you can export the source code and change the data element's NULLable ... for example:

From

<return name='returnvalue' type='System.Int16' isRef='False' ArrayDim='0' IsNullableType='False' />

To

<return name='returnvalue' type='System.Int16' isRef='False' ArrayDim='0' IsNullableType='TRUE />

Former Member
0 Kudos

Excellent! I shall give that a try straight after lunch. Thanks for your help!

Former Member
0 Kudos

As usual complications have arisen. Powerbuilder Classic requires the old XML Serialization, and the XML Serialization can't handle nullable datatypes (good old Microsoft, if only they'd talked to some database guys before writing .NET, perhaps a SQL Server developer?). However I see mention of overiding the serialization of the nullable dataypes so they can be serialized to XML, and I'm going to give that a try, why the hell not! I'll report back any findings here in case anyone else is interested.

Former Member
0 Kudos

I think I've got it!!!! Thanks everyone for the hints that have pointed me to the answer (at least it looks good to me at the moment who knows what will come up next).

Here's a summary of it all in case someone else searches this for similar things.

I want to be able to create a Web Service datawindow in Powerbuilder Classic 11.5 (or 12.5 or 15). I want the web service to be a WCF .NET C# application. The limitations I have found so far are the endpoint binding must be basicHttpBinding meaning it is a SOAP 1.1 service (RESTful not allowed). I have seen mention of SOAP 1.2 and PowerBuilder online, but in this case it has to be SOAP 1.1. If your datawindow creates okay, but hangs when retrieving then you're probably not using the basicHttpBinding. The second limitation is that the data must be returned using the XML serialization contract, rather than the Data Contract Serialization that the more recent versions of Visual Studio default to. You do this by decorating your interface class with [XmlSerializerFormat] and your returned attributes with [XmlAttribute]. However if you want to return a nullable value, e.g. int? rather than int (and who wouldn't), then instead of adding [XmlAttribute] you add [XmlElement(IsNullable=true)] and somehow this makes it all work.

Here is an interface class example:

    [ServiceContract]

    [XmlSerializerFormat]

    public interface IClientService

Here are some attributes indicating what will be returned to the datawindow, note how the ClientParentRef allows null values to be returned:

    [DataContract]

    public class Client

    {

        int clientRef;

        string clientName;

        int clientParentRef;

        [XmlAttribute]

        public int ClientRef { get; set; }

        [XmlAttribute]

        public string ClientName { get; set; }

        [XmlElement(IsNullable=true)]

        public int? ClientParentRef { get; set; }

    }

Hope this proves useful to someone one day

Former Member
0 Kudos

Congratulations Aron. You're so much smarter now... and so are we!

If you would of had the option to create the WCF in PB.net you wouldn't of had to do all that and your service could have been used from either PB Classic or PB.Net as a datawindow source.

Former Member
0 Kudos

  I think you meant to say  ... "If you would of had the option to create the WCF in PB Classic you wouldn't of had to do all that". 

Former Member
0 Kudos

I must admit I think I will try doing it from PB.NET next just to see the difference. This time I was told to see what we could do in terms of our PB classic app and C# Web Service. It will be interesting to see what I can do with WCF in PB.NET.

Former Member
0 Kudos

Your forgot to say Appeon in your post.

Former Member
0 Kudos

Hi Aron,

I created WCF target with one dw, structure and nvo. The nvo had one method to retrieve the dw.

I created a WPF target with one window and dw with the WCF as the data source.

I created a win32 target with one window and dw with the WCF as the data source.

No hacks or work arounds and took just a few minutes.

The WCF was self-hosted which is great for developing because you don't have to fool with IIS.

hth,

Mark

Answers (0)