Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Passing Nulls to WCF (Published Orch)
- This topic has 7 replies, 1 voice, and was last updated 9 years ago by
community-content.
-
AuthorPosts
-
-
September 9, 2008 at 12:48 PM #20656
We have a C# GUI application (VS2008/.NET 3.5) that wants to pass nulls to certain fields (in order to eventually nullify a field in the database).
This article seems to cover many good points – but leaves one hanging with no easy solution:
http://bytes.com/forum/thread375805.htmlWhen the C# consumes the web service (published orchestration), the proxy doesn’t seem to have any allowance for nulls.
For example, one of our decimal fields is defined in the proxy like this:
[System.Runtime.Serialization.
OptionalFieldAttribute()]
private decimal CurrentGrossRateField;
[System.Runtime.Serialization.DataMemberAttribute(Order=56)]
public decimal CurrentGrossRate {
get {
return this.CurrentGrossRateField;
}
set {
if ((this.CurrentGrossRateField.Equals(value) != true)) {
this.CurrentGrossRateField = value;
this.RaisePropertyChanged(“CurrentGrossRate”);
}
}
}In the schema used by the orchestration, the field is defined as minOccurs=0, maxOccurs=1, and Nillable= True
What happens to the “Nillable=True”? Does this not float over to the C# proxy somehow?Thanks,
Neal Walters -
September 9, 2008 at 3:32 PM #20659
Can you describe the problem a little more? Are the null fields causing a runtime error, or are you not able to set fields to null at design time?
-
September 10, 2008 at 12:07 PM #20682
In C# (starting with .NET 2.0)
decimal currGrossRate1 = null; // this line will not compiled
decimal? currGrossRate2 = null; // this line is okayThe GUI application needs to either set a field to zero or null, depending on some logic.
See also: http://bytes.com/forum/thread375821.html and http://bytes.com/forum/thread375805.html
Key part of the second link is this: “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 “propertyName”,
if there is a companion property named “propertyNameSpecified” which is a
bool, then the propertyNameSpecified indicates whether the property of name
“propertyName” is nil or not.”If I remember correctly, with .asmx web services, there was an “isSpecified” for every single optional element (or element that had minOccurs=0). That seems to be totally gone with WCF, at least the proxies generated when you connect to an orchestration published as a WCF.
Thanks,
Neal-
September 11, 2008 at 9:13 AM #20694
Here’s more info as I continue to investigate:
1) I have a field in my XML called CurrentGrossRate that has “Nillable” set to true (and minOccurs=0).
2) The C# proxy generated by doing an “Add Service Reference” generates the following definition:
[System.Runtime.Serialization.
OptionalFieldAttribute()]
private decimal CurrentGrossRateField;The corresponding property is defined as follows:
[System.Runtime.Serialization.DataMemberAttribute(Order=56)]
public decimal CurrentGrossRate {
get {
return this.CurrentGrossRateField;
}
set {
if ((this.CurrentGrossRateField.Equals(value) != true)) {
this.CurrentGrossRateField = value;
this.RaisePropertyChanged(“CurrentGrossRate”);
}
}
}3) There is no fiedl called CurrentGrossRateSpecified nor CurrentGrossRateIsSpecified or anything similar.
4) Using the proxy, I get a compile error if I do this:
loan1.CurrentGrossRate =
null;
error CS0037: Cannot convert null to ‘decimal’ because it is a non-nullable value type
5) I created an xml file with the field CurrentGrossRate missing, and have the C# test program deserialize it. I immediately show the value of the field CurrentGrossRate and it’s value is zero.
Thanks,
Neal-
September 11, 2008 at 9:44 AM #20695
Maybe you could use svcutil to generate the proxy, and then make updates like the following:
decimal CurrentGrossRate;
->
decimal? CurrentGrossRate;
The svcutil proxy would be a C# file you could keep in source control, so it is a little less likely to get overwritten than a service reference.
-
September 12, 2008 at 8:30 AM #20709
One of our ideas was to override the proxy, but I like your idea of putting it in a different location.
A co-worker is doing a similar project to mine, and surprisingly, he has the “Specified” suffixes on almost all of his fields. I cannot figure out why he has them and I don’t. We both have minOccurs=0. He tried changing a Nillable from false to true, and still has the Specified suffix.
Another question is how to handle nulls on a retrieval. Suppose we do a getData from a database, and it it has nulls. How do we get those nulls to deserialize back into C# GUI program (that calls the orch – published as websvc)?
Thanks,
NealP.S. Did Steve do a “tag your it”? His photo was a dog with it’s tongue hanging out, and now his photo is normal, and your photo is a dog with it’s tongue hanging out. Hmmmm???
-
September 12, 2008 at 9:00 AM #20710
Not sure how you would get the nulls to deserialize back into C#. I would do some experimentation with the different XML options. For example, what happens if your orch returns an XML that omits the field? What happens if it returns an XML where the field is there, but with no value (<CurrentGrossRate />).
No, it wasn’t a tag-your-it. I like to use my dog as my picture, because she is much better looking than me[:P].
-
July 8, 2009 at 7:28 PM #22821
wsdl.exe (used with the older ASMX web services) generates proxy with the “Specified” convention.
ASMX web services stack was part of the .Net 1.0 and 1.1 framework. There were no way to represent null values for value types. Hence, the “Specified” convention. WCF does not use this convention because .Net 2.0 supports nullable types.
if you guys are generating the proxy class file in the command prompt, your co-worker may have been wsdl.exe (ASMX web service) to generate the proxy while you’re using svcutil.exe (WCF web service).
if Visual Studio is generating the proxy class file, he could be using Visual Studio 2005, without the WCF extension and/or .Net 3.0 installed.
Make sure the WSDL complies to the Data Contract Schema Reference. http://msdn.microsoft.com/en-us/library/ms733112.aspx
Check the published web service code and make sure, the service contract is using T? or Nullable<T>.
HTH,
An Phu
-
-
-
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.