473,549 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Consuming WebService which returns NULL-values

Hello,

I'd like to consume a WebService, which returns an array of objects which
include several members of type System.String, System.Decimal and
System.DateTime .
In the WSDL-file, the members of the object are marked as nilable.
I generated the client classes using VS.NET 2003. After the creation, I got
the class-definition of the objects returned by the WebService too. BUT,
only the System.String members where marked to be nullable, System.Decimal
and System.DateTime don't. Ok, I know, they are value-types and cannot be
NULL, but thats exactly my problem.
If I then call the service, and it returns, I get an System.InvalidO peration
exception.
If I change the datatypes of the decimal and datetime-members to
System.Object, everything works, but I have to do the value-conversion
myself.

Is there a better way for solving that problem? I don't want to edit the
generated files everytime I regenerate them.

Thanks very much!
Max
Nov 16 '05 #1
6 6506
There is a convention in .NET XML Serialization (which is used by the
webservices runtime) that allows value-types to be marked as "nil".
The convention is, for each property in a class with a name "propertyNa me",
if there is a companion property named "propertyNameSp ecified" which is a
bool, then the propertyNameSpe cified indicates whether the property of name
"propertyNa me" is nil or not.

See
http://msdn.microsoft.com/library/en...ClassTopic.asp
for the doc on this.

For example, this complexType in XML Schema:
<s:complexTyp e name="IdType">
<s:sequence>
<s:element name="Name" minOccurs="0" maxOccurs="1"
type="s:string" nillable="true" />
<s:element name="Stamp" minOccurs="0" maxOccurs="1"
type="s:date" nillable="true" />
<s:element name="Id" minOccurs="0" maxOccurs="1"
type="s:int" nillable="true" />
</s:sequence>
</s:complexType>

will generate something like this type definition in C#:

[XmlType(Namespa ce="urn:myNameS paceHere")]
public class IdType {
[XmlElement(IsNu llable=true)] public string Name;

[XmlElement(Data Type="date")] public System.DateTime Stamp;
[XmlIgnore] public bool StampSpecified;

[XmlElement] public int Id;
[XmlIgnore] public bool IdSpecified;
}

---------

Notice that the string (not a value type) is marked IsNillable=true , while
the int and DateTime (both value types) are not. In your app code, to
deal with nil values in the string, you do this:

if (instance.Name != null) ...

Conversely, to deal with nil values on value types (like the int and
DateTime), what you need to do is

if (instance.Stamp Specified) ....
if (instance.IdSpe cified) ....

The Id and Stamp will never actually be nil, but you treat them as nil in
app code if the flag says that they are not specified. The same convention
applies to all value types in .NET.

--------

So, can you examine the generated files and tell me if you have the
companion xxxSpecified properties marked "XmlIgnore" ? If so, then you
know what to do. . .

-Dino


"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

I'd like to consume a WebService, which returns an array of objects which
include several members of type System.String, System.Decimal and
System.DateTime .
In the WSDL-file, the members of the object are marked as nilable.
I generated the client classes using VS.NET 2003. After the creation, I got the class-definition of the objects returned by the WebService too. BUT,
only the System.String members where marked to be nullable, System.Decimal
and System.DateTime don't. Ok, I know, they are value-types and cannot be
NULL, but thats exactly my problem.
If I then call the service, and it returns, I get an System.InvalidO peration exception.
If I change the datatypes of the decimal and datetime-members to
System.Object, everything works, but I have to do the value-conversion
myself.

Is there a better way for solving that problem? I don't want to edit the
generated files everytime I regenerate them.

Thanks very much!
Max

Nov 16 '05 #2
Dino,

thanks for your reply!

We now added the "minOccurs" and "maxOccurs" settings into our WSDL-file and
updated the server- and client-classes. Now it works fine because it just
doesn't send the NULL-values to the client.
Previously we didn't specify these two attributes.

But, what if I absolutely don't have a chance to modify the server-WSDL?
Let's say that the attributes are specified like this:
<s:element name="Stamp" minOccurs="1" maxOccurs="1" type="s:date"
nillable="true" />

So I won't have a chance to consume this service the "easy" way!

I wonder why there is no functionality in the .NET serialization, which
supports something like
[XmlIgnore] public bool StampIsNull;

What do you think?

Max
"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
There is a convention in .NET XML Serialization (which is used by the
webservices runtime) that allows value-types to be marked as "nil".
The convention is, for each property in a class with a name "propertyNa me", if there is a companion property named "propertyNameSp ecified" which is a
bool, then the propertyNameSpe cified indicates whether the property of name "propertyNa me" is nil or not.

See
http://msdn.microsoft.com/library/en...ClassTopic.asp for the doc on this.

For example, this complexType in XML Schema:
<s:complexTyp e name="IdType">
<s:sequence>
<s:element name="Name" minOccurs="0" maxOccurs="1"
type="s:string" nillable="true" />
<s:element name="Stamp" minOccurs="0" maxOccurs="1"
type="s:date" nillable="true" />
<s:element name="Id" minOccurs="0" maxOccurs="1"
type="s:int" nillable="true" />
</s:sequence>
</s:complexType>

will generate something like this type definition in C#:

[XmlType(Namespa ce="urn:myNameS paceHere")]
public class IdType {
[XmlElement(IsNu llable=true)] public string Name;

[XmlElement(Data Type="date")] public System.DateTime Stamp;
[XmlIgnore] public bool StampSpecified;

[XmlElement] public int Id;
[XmlIgnore] public bool IdSpecified;
}

---------

Notice that the string (not a value type) is marked IsNillable=true , while
the int and DateTime (both value types) are not. In your app code, to
deal with nil values in the string, you do this:

if (instance.Name != null) ...

Conversely, to deal with nil values on value types (like the int and
DateTime), what you need to do is

if (instance.Stamp Specified) ....
if (instance.IdSpe cified) ....

The Id and Stamp will never actually be nil, but you treat them as nil in
app code if the flag says that they are not specified. The same convention applies to all value types in .NET.

--------

So, can you examine the generated files and tell me if you have the
companion xxxSpecified properties marked "XmlIgnore" ? If so, then you
know what to do. . .

-Dino


"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hello,

I'd like to consume a WebService, which returns an array of objects which include several members of type System.String, System.Decimal and
System.DateTime .
In the WSDL-file, the members of the object are marked as nilable.
I generated the client classes using VS.NET 2003. After the creation, I

got
the class-definition of the objects returned by the WebService too. BUT,
only the System.String members where marked to be nullable, System.Decimal and System.DateTime don't. Ok, I know, they are value-types and cannot be NULL, but thats exactly my problem.
If I then call the service, and it returns, I get an

System.InvalidO peration
exception.
If I change the datatypes of the decimal and datetime-members to
System.Object, everything works, but I have to do the value-conversion
myself.

Is there a better way for solving that problem? I don't want to edit the
generated files everytime I regenerate them.

Thanks very much!
Max


Nov 16 '05 #3

"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:uq******** ******@tk2msftn gp13.phx.gbl...
But, what if I absolutely don't have a chance to modify the server-WSDL?
Let's say that the attributes are specified like this:
<s:element name="Stamp" minOccurs="1" maxOccurs="1" type="s:date" nillable="true" />
So I won't have a chance to consume this service the "easy" way!

Let's not discuss whether it actually makes sense to have a minOccurs=1
element be nillable. Suppose that it does make sense.
Generating a proxy class from this WSDL will NOT generate the StampSpecified
bool property.

This seems broken. However, you can easily add it in yourself. (I know you
said you did not want to modify the generated files, but the point is you
could do so)

The other option is to modify the server-side WSDL before you use it to
generate code. I often do this to rename artifacts or fixup things that I
know, through testing, are broken. For example, a service is sending an
xsd:date, but the WSDL specifies an xsd:dateTime. And so on. So you
could just snapshot the WSDL and tweak it a bit.

I wonder why there is no functionality in the .NET serialization, which
supports something like
[XmlIgnore] public bool StampIsNull;

What do you think?


How would this be different from the StampSpecified mechanism that is
currently supported ?

-D
Nov 16 '05 #4
Please see below ...

Max

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:uW******** *****@TK2MSFTNG P12.phx.gbl...

"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:uq******** ******@tk2msftn gp13.phx.gbl...
But, what if I absolutely don't have a chance to modify the server-WSDL?
Let's say that the attributes are specified like this:
<s:element name="Stamp" minOccurs="1" maxOccurs="1" type="s:date" nillable="true" />

So I won't have a chance to consume this service the "easy" way!


Let's not discuss whether it actually makes sense to have a minOccurs=1
element be nillable. Suppose that it does make sense.
Generating a proxy class from this WSDL will NOT generate the

StampSpecified bool property.

This seems broken. However, you can easily add it in yourself. (I know you said you did not want to modify the generated files, but the point is you
could do so)

The other option is to modify the server-side WSDL before you use it to
generate code. I often do this to rename artifacts or fixup things that I
know, through testing, are broken. For example, a service is sending an
xsd:date, but the WSDL specifies an xsd:dateTime. And so on. So you
could just snapshot the WSDL and tweak it a bit.

I wonder why there is no functionality in the .NET serialization, which
supports something like
[XmlIgnore] public bool StampIsNull;

What do you think?
How would this be different from the StampSpecified mechanism that is
currently supported ?


The problem is: If I'm not able to make changes to the server side WSDL
(if I use a service offered by a 3rd party company, which doesn't want to
modify it and more), and they have minOccurs="1" (or lets say, they just
forgot to make the minOccurs definition, which I think defaults to 1),
they send the fields containing a null value. Now, AFAIK, .NET is NOT
able to consume this service! Even that NULL values are included in the
XML specification, it won't be possible to consume that service, because
the field does come down from the server (StampSpecified =true), BUT
it contains NULL, which cannot be mapped to any System.DateTime .
Here a StampIsNull=tru e would help a lot.

But I just read about the nullable types in .NET 2.0. Maybe there is some
solution for this!


-D

Nov 16 '05 #5

"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:u0******** ******@TK2MSFTN GP09.phx.gbl...
Please see below ... The problem is: If I'm not able to make changes to the server side WSDL
(if I use a service offered by a 3rd party company, which doesn't want to
modify it and more), and they have minOccurs="1" (or lets say, they just
forgot to make the minOccurs definition, which I think defaults to 1),
they send the fields containing a null value. Now, AFAIK, .NET is NOT
able to consume this service! Even that NULL values are included in the
XML specification, it won't be possible to consume that service, because
the field does come down from the server (StampSpecified =true), BUT
it contains NULL, which cannot be mapped to any System.DateTime .
Here a StampIsNull=tru e would help a lot.

Ahh, ok, I see. Yes, you are correct.
You are getting from the server
<Stamp isNil="true" />

in which case, the XML Serializer chokes. So you would need to do some
fancy footwork on the client side in order to de-serialize a nil DateTime.
But I just read about the nullable types in .NET 2.0. Maybe there is some
solution for this!

yes, in 2.0.
In v1.1, I think you have work to do. It is not easy, but it is possible.

This is the default definition for a <xsd:dateTime > .

public class MyType {
public System.DateTime DateTimeField;
}

If you modify it to something like this, you may get the behavior you want:
public class MyType {
private static string formatString= "yyyy-MM-ddTHH:mm:ss.fff ffffzzz";
private static System.Globaliz ation.CultureIn fo CInfo= new
System.Globaliz ation.CultureIn fo("en-US", true);

[XmlIgnore] public System.DateTime internal_DateTi meField;
[XmlIgnore] public bool DateTimeFieldIs Null; // ideally this would be
provided by .NET, but it isn't.

[XmlElement(IsNu llable=true)]
public string DateTimeField {
set {
if ((value!=null) && (value != "")) {
internal_DateTi meField= System.DateTime .ParseExact(val ue,
formatString, CInfo);
DateTimeFieldIs Null= false;
}
else
DateTimeFieldIs Null= true;
}
get {
return (DateTimeFieldI sNull) ?
null :
internal_DateTi meField.ToStrin g(formatString) ;
}
}
}
-D
Nov 16 '05 #6
Thanks very much for your answer.
I'll try to use it somehow, but it'll take a while! ;-)

Max

"Dino Chiesa [Microsoft]" <di****@online. microsoft.com> wrote in message
news:eL******** ******@TK2MSFTN GP12.phx.gbl...

"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:u0******** ******@TK2MSFTN GP09.phx.gbl...
Please see below ...
The problem is: If I'm not able to make changes to the server side WSDL
(if I use a service offered by a 3rd party company, which doesn't want to modify it and more), and they have minOccurs="1" (or lets say, they just
forgot to make the minOccurs definition, which I think defaults to 1),
they send the fields containing a null value. Now, AFAIK, .NET is NOT
able to consume this service! Even that NULL values are included in the
XML specification, it won't be possible to consume that service, because
the field does come down from the server (StampSpecified =true), BUT
it contains NULL, which cannot be mapped to any System.DateTime .
Here a StampIsNull=tru e would help a lot.


Ahh, ok, I see. Yes, you are correct.
You are getting from the server
<Stamp isNil="true" />

in which case, the XML Serializer chokes. So you would need to do some
fancy footwork on the client side in order to de-serialize a nil DateTime.
But I just read about the nullable types in .NET 2.0. Maybe there is some solution for this!

yes, in 2.0.
In v1.1, I think you have work to do. It is not easy, but it is

possible.
This is the default definition for a <xsd:dateTime > .

public class MyType {
public System.DateTime DateTimeField;
}

If you modify it to something like this, you may get the behavior you want: public class MyType {
private static string formatString= "yyyy-MM-ddTHH:mm:ss.fff ffffzzz";
private static System.Globaliz ation.CultureIn fo CInfo= new
System.Globaliz ation.CultureIn fo("en-US", true);

[XmlIgnore] public System.DateTime internal_DateTi meField;
[XmlIgnore] public bool DateTimeFieldIs Null; // ideally this would be provided by .NET, but it isn't.

[XmlElement(IsNu llable=true)]
public string DateTimeField {
set {
if ((value!=null) && (value != "")) {
internal_DateTi meField= System.DateTime .ParseExact(val ue,
formatString, CInfo);
DateTimeFieldIs Null= false;
}
else
DateTimeFieldIs Null= true;
}
get {
return (DateTimeFieldI sNull) ?
null :
internal_DateTi meField.ToStrin g(formatString) ;
}
}
}
-D

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5217
by: mzam | last post by:
Hi everyone, I have a vbscript which is consuming WebMethods from a WebService. Whenever the WebMethod returns a string or integer then no problem but when the WebMethod returns a DataSet then the following error appears: Error: Attachment:Maximum retry on the connection exceeded. HRESULT=0x80004005: Unspecified error - Client:An...
1
2809
by: Parag Mahajan | last post by:
Hi, I am developing a .Net client for Axis 1.1 web service written in java. The wsdl is generated using, java2WSDL with these switches:: -y WRAPPED -u LITERAL The login service which returns a session Id, is null, after deserializing, but when the XML passing over wire is seen, I can see the session Id being returned. But if in the client...
0
1156
by: Srinivas Kotta | last post by:
Hi, I am Trying to get the Array of claases from Webservice which returns an array of classes. that webservice is returned in Java and i am consumin g that webservice in ASP.Net. my problem is i am able to get the data from that webservice but it is limited to 1024 Classes..
0
1814
by: Sathya | last post by:
Hi, I have a vb.net webservice which takes XMLDocument as a parameter and returns bool. Signature of the method is some thing like this AddXmlEmpDetails(xmlEmp as XMLDocument) as Boolean. I am able to call this method from vb.net desktop client and add a record to the database(this I used to test if there is any problem in the...
0
1586
by: Alexiel | last post by:
Hi, i have a problem, I have a Java Client and i call my webservice on ..NET. This run perfectly just except when i send parameters don't work fine. I send my code : This is my java client..........
4
5982
by: Boni | last post by:
I want consuming a webserivce trough a proxy. I use this code. myService s = new myService (); System.Net.WebProxy proxyObject = new System.Net.WebProxy("http://proxyhost:8080"); s.Proxy = proxyObject; It doesn't works, it returns a error HTTP 407: Proxy Authentication Required ( Access is denied. ). But my proxy don't need a user...
0
1356
by: Rob C | last post by:
I have several methods implemented in a webservice written in C#. The methods execute SQL against a SQL Server 2005 db and returns a Dataset (as XML). I am utilizing the webservice from a VC++ app by adding the web ref to the project which creates the header file for making the calls. I traced through the method call in my app and found the...
3
6089
by: Jeremy Chapman | last post by:
I've writtin a very simple web service in axis which returns an array of classes. I consume it in a .net app. When receiving the response, my .net app generates an error "Cannot assign object of type System.Object to an object of type PersonWS.WorkGroupData.". I've included the wsdl of the consumed axis web service, the...
0
2869
by: gabrielk43 | last post by:
Hi I am new to Flex and I use Flex Builder 2 to make a web service client. So I have a web service in .NET(c#) with a simple web method that returns a string(no arguments). It works, I tested it using firefox. I have managed to consume the service in Flex by using MXML like this: <mx:WebService id="wsTestWebService"...
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.