optional nillable values

Hi,

I have added an optional nillable element to a schema like this -
....
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:int"
nillable="true"/>
....


A class is generated from this using xsd.exe and which is used by a web
service where it makes it's way into the wsdl as:

  <s:element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
type="s:int" />


Now when the client consumes the web service I get a class

class Thing
{
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Nullable<int> Id;

[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IdSpecified {

}

Which is what I expected.  Now however if I specify

Thing t = new Thing();
t.Id = 1;
t.IdSpecified = true;

and send this to the web service it is received as Id=1, IdSpecified=false
which is not what I expected.

Similarly when data is retrieved from the web service the IdSpecified is 
always false even if there's data in Id.

I would really expect to be able to optionally send a value or a null value.

Regards
Phil Lee






0
phil.lee (3)
1/18/2006 5:25:21 PM
dotnet.xml 7266 articles. 0 followers. Follow

6 Replies
599 Views

Similar Articles

[PageSpeed] 28


Phil Lee wrote:


> I have added an optional nillable element to a schema like this -
> ...
> <xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:int"
> nillable="true"/>
> ...
> 
> 
> A class is generated from this using xsd.exe and which is used by a web
> service where it makes it's way into the wsdl as:
> 
>   <s:element minOccurs="0" maxOccurs="1" name="Id" nillable="true"
> type="s:int" />

You might want to ask in 
microsoft.public.dotnet.framework.aspnet.webservices for web service 
related stuff.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
1/18/2006 6:16:17 PM
Hi Phil,

I think you can modify the IdSpecified method like the following:

[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IdSpecified {
    if(this.Id.HasValue)
        return true;
    else
        return false;
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no 
rights."

0
v-kevy (347)
1/19/2006 2:41:57 AM
Kevin,

ok, thanks.  I don't like modifying auto-generated code though - it tends to 
get overwritten.

Is this a bug?  Or do I not understand nillable correctly - which is quite 
possible.

I understood or hoped that nillable meant that an explicit 'nil' value could 
be sent to represent a null.  Which is different from not sending the 
element.  So I would expect to be able to:
    1) not send the element which would result in the Specified flag being 
false
    2) send the element with a value which would result in the flag being 
true and the value being non-null
    3) send the element with a nil-value which would result in the flag 
being true and the value being null
which would then be represented quite nicely by a System.Nullable<> and a 
FieldSpecified flag.

Regards
Phil Lee

"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message 
news:mOcN1HKHGHA.3152@TK2MSFTNGXA02.phx.gbl...
> Hi Phil,
>
> I think you can modify the IdSpecified method like the following:
>
> [System.Xml.Serialization.XmlIgnoreAttribute()]
> public bool IdSpecified {
>    if(this.Id.HasValue)
>        return true;
>    else
>        return false;
> }
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
> 


0
phil.lee (3)
1/19/2006 6:16:45 PM
Hi Phil,

Thanks for your feedback. Yes, it seems to be a bug, with my search. You 
can check the following link for detail.

http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=c
1dbdc79-db80-4cc1-b392-e6f6e457db85

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no 
rights."

0
v-kevy (347)
1/20/2006 6:44:29 AM
Kevin,

I think what I'm asking is slightly different from the "bug" you refer to.

If I have this class/schema:

....
    <xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:int"/>
....

class Customer
{
    public int Id;
    [XmlIgnore()]
    public bool IdSpecified;
}

I can use it like this:

    Customer test = new Customer();
    test.Id = 2;
    test.IdSpecified = true;

now send it somewhere via xml serialization and it arrives with Id=2 and
IdSpecified=true.   Note there isn't any special code to set the specified 
flag to true when
the Id field is set.  It just happens as part of the deserialization 
process.

If I have this (nillable value):

....
    <xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:int"
nillable="true"/>
....

class Customer
{
    public int? Id;
    [XmlIgnore()]
    public bool IdSpecified;
}

And I use it in the same way:

    Customer test = new Customer();
    test.Id = 2;
    test.IdSpecified = true;

If I send it somewhere via xml serialization it arrives with Id=2 and
IdSpecified=false which is wrong.  The specified flag is always false after 
deserialization
regardless of the value of Id and of the specified flag before 
serialization.

Look at these examples:

Value being sent before serialization: IdSpecified=true, Id=null
Serialized xml:                                  <Customer>  <Id 
xsi:null="true" /> </Customer>
Deserialized:                                    IdSpecified=false, Id=null

Value being sent before serialization: IdSpecified=false, Id=null or any 
non-null value
Serialized xml:                                  <Customer>  </Customer>
Deserialized:                                    IdSpecified=false, Id=null

Value being sent before serialization: IdSpecified=true, Id=4
Serialized xml:                                  <Customer>  <Id>4</</Id> 
</Customer>
Deserialized:                                    IdSpecified=false, Id=4

The serialized xml is what I would expect.  The deserialized data is wrong 
because there is no way to distinguish a missing (optional) value from an 
explict null value.

Regards
Phil



"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
news:CjSZA0YHGHA.3944@TK2MSFTNGXA02.phx.gbl...
> Hi Phil,
>
> Thanks for your feedback. Yes, it seems to be a bug, with my search. You
> can check the following link for detail.
>
> http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=c
> 1dbdc79-db80-4cc1-b392-e6f6e457db85
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>



0
phil.lee (3)
1/20/2006 1:45:50 PM
Hi Phil,

It seems to have something to do with the web service. I suggest you try to 
post it in the web service newsgroup. Maybe there will be more 
professionals who can answer this question there.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no 
rights."

0
v-kevy (347)
1/23/2006 12:43:06 PM
Reply:

Similar Artilces:

Overlapping of values in different tables.
I am wondering if there is a way to create a pivot table - or some other way - that will show the relationships of rows between tables. I have attached data from potentially 4 different tables and the business is wanting to see the number of times that a paticular ID shows up in different table join combinations. For example, we want to know the count of unique IDs will show in the NPS, AAC and ECM tables. Is it possible to create a pivot table that will dynamically adjust based on a user choosing the column combinations that they want to see without having to create a separate pivot...

Is there an option in Outlook '03 to confirm before closing?
Many times I will inadvertantly X out of Outlook and will have synch issues when I restart immediately. Is there an option that asks "Are you sure you want to close Outlook?" I know there is an option that asks to confirm before permanently deleting messages, but I haven't found one that will allow you to abort closing Outlook. Any ideas? "Cashman" <Cashman@discussions.microsoft.com> wrote in message news:FF1544E7-0D2F-4BC8-8BC0-FEA9EC40FEA5@microsoft.com... > Many times I will inadvertantly X out of Outlook and will have synch issues > when ...

find location max value in column
I need to find the cell location of the max value in a column. If paste the following [from =(cell onwards] into a cell I get the righ result. Having a hgard time getting the right VBA code to make thi work in an unattended macro. Probably some bonehead mistake on my part but I cannot find it. Suggestions? GOAL is to make this formula work. Range("z2").Formula "=(CELL(e1,OFFSET(e1,MATCH(MAX(e1:e100),e1:100,0)-1,0)))" TIA, Ro -- rroac ----------------------------------------------------------------------- rroach's Profile: http://www.excelforum.com/member.php?act...

Retrieving default values specified from XML Schema file
Hi All, I have an VS.NET 2003 app which will be processing XML files, some of which will have empty elements (for example, <Item />). I have an XSD file which should supply default values, but I am not able to read these plugged in value using an XMLDocument object. The validation is working fine--it's just not providing any default values. Has anybody tried this? Am I must be missing something? This is one of those that "should be simple..." Here's a simplifed version of the code and XML files: XmlDocument xmldoc = new XmlDocument(); XmlSchemaCollection my...

Creating drop down lists with multiple options?
I am trying in vain to create a drop down list where users can select more than 1 choice. For example, if the choices in a list which i named are as follows: Blue Red Green Yellow Purple How does one have the option to select any of the colors by themselves or any combination of all of them up? For example, if the question is what is your favorite color? How can a user choose Blue OR Red and Blue OR Red, Blue and Green and so on? Any help would be appreciated. That will require multiple cells. One cell will only hold 1 value. Any single cell solutions are going ...

multi-value field
I'm still learning Access, so I must apologize in advance for my question. I have four tables, tblBrochure, tblStaff, tblOrganization, tblResourceDistribution. tblBrochure has two fields -BrochureName -Active (y/n) tblStaff has two fields -StaffName -Active (y/n) tblOrganization has two fields -OrgName -textbox (0 and 1, explained below) tblResourceDistribution has 5 fields -DistribDate -StaffName (lookup from tblStaff ->Staffname -Organization (lookup from tblOrganization ->OrgName) ...

Lookup value selection
Is there any way to select lookup value by pressing "Enter" key on keyboard and avoid mouse click? -- romeo!! Please clarify. I could use the up and down arrow to select the values and then press "Enter" key to select the lookup value - works for me in v4.0. Frank Lee, Microsoft Dynamics CRM MVP http://www.workopia.com/Links.htm http://microsoft-crm.spaces.live.com "romeo" wrote: > Is there any way to select lookup value by pressing "Enter" key on keyboard > and avoid mouse click? > > -- > romeo!! ...

Vlookup
Dear all, For vlookup, it will return the value of the destination cell. Is it possible to return the row no. instead of value of the destination cell?? Your help is highly appreciated. Thanks & regards, Automne Look at the MATCH function in Help. On Sat, 5 Mar 2005 01:41:39 +0800, "automne" <hersbt_no_spam@yahoo.com.hk> wrote: >Dear all, > >For vlookup, it will return the value of the destination cell. Is it >possible to return the row no. instead of value of the destination cell?? > >Your help is highly appreciated. > >Thanks & regards,...

How to ignore records with a duplicate ID based on a value
I hae searched the forum tono avail, so I'll ask for help. I have a table [Scope Event Table] which records events with status changes. The table uses an auto numbered primary key (not shown in the example below). It has data like this: DR_ID Event_Date Reason 12556 01/03/2008 Added 12556 01/24/2008 Closed 12874 01/05/2008 Added 14128 02/09/2008 Added I am a novice at SQL. I am trying to build a query that would pull only the DR_ID’s where the most recent Reason = “Added”. So I would want results to look like this: DR_ID Event_Date Reason 12874 01/05/2008 Added 14128 02/09/2008...

merging a value in a text field with each line in a memo field
I am trying to merge a value in a text field with the information in a memo field using a query to create a report. This is the query I am using: SELECT AVRelay+","+IPRange FROM T_Sites AVRelay is the text field and IPRange is the Memo. IPRange has multiple lines, each of which I need appended with the value in AVRelay for the report. It should look like. 2,192.168.1.0/24 2,192.168.0.0/24 2,192.168.2.0/24 Instead it looks like 2,192.168.1.0/24 192.168.0.0/24 192.168.2.0/24 I have searched far and wide but has come up empty. Please help! I would gues...

Set default values
I've set up a template where I have headers and cell validations. I want to be able to have some of the fileds in the row autopopulate once the first cell in the row is entered. Do you know of a way that I can code this using VBA. For example, A3 is populated with a value, I then want G3 to be updated with a "1". -- Message posted via http://www.officekb.com In G3: =IF(A3="","",1) -- Gary''s Student - gsnu2007k In G3 use the formula =IF(A3<>"",1,"") The "" is a pair of double-quotes with no space between be...

Sending value to a cell
Hi there, I want to dump a computed value into a cell that isn't the one the calculation was done in. Can it be done from the original cell? Hi no, not with a formula -- Regards Frank Kabel Frankfurt, Germany "CM32134" <CM32134@discussions.microsoft.com> schrieb im Newsbeitrag news:0768C79B-586C-42CB-A7AE-1A817C4CE5F5@microsoft.com... > Hi there, > I want to dump a computed value into a cell that isn't the one the > calculation was done in. Can it be done from the original cell? A worksheet formula returns a value and can do nothing else. Think...

Disable Autofil options
Hi I have Excel 2003 SP2, when I am woring in a spreadsheet a little square pops up that says "autofil options" when I hold the cursor over it. How do I stop this from happening. thanks Tools>Options>Edit. Uncheck the "show insert options buttons" I also uncheck the "show paste options buttons". You can also go into Error Checking tab and maybe get rid of a few of those. Gord Dibben MS Excel MVP On Sun, 4 Feb 2007 14:15:00 -0800, Daniel - Sydney <DanielSydney@discussions.microsoft.com> wrote: >Hi > >I have Excel 2003 SP2, when I...

Exchange 2k7 powershell truncates multi-value properties
Greetings, I'm running the following command: Get-SendConnector -Identity "Send Connector Name" | ft -autosize -wrap -property AddressSpaces We have over 20 domains in this list. When I run this command it lists 16 of these domains and then just sticks ... at the end. If I leave out the -wrap switch the output lists only 3 domains. How can I get this command to list ALL the contents of the AddressSpaces property? Thanks Try to pipe to format-list instead. --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic...

I am making a charts with weird X-values for my Ecology cl\
i am making a chart with weird X-values. Instead of single, whole numbers, I need each value to be as follows: 1-2, 3-5, 6-10, 11-15, etc. Please help me!! My chart keeps going to whole numbers instead and its been driving me crazy for days! What chart type are you using? If you want your X-axis to be category labels, rather than actual numbers, you may find that a line chart (or one of the other chart types) is more suitable than an XY (scatter) chart, if the latter is what you are currently trying. -- David Biddulph "Holly" <Holly@discussions.microsoft.com> wro...

How to round the numeric value?
Kindly tell me that how can we round the numeric value? Example: 1.2 = 1.5, 1.7 = 2.0 "Salman Saeed" <Salman Saeed@discussions.microsoft.com> wrote in message news:F5460D85-6DEE-4EC5-8E83-A1A5E158966A@microsoft.com... > Kindly tell me that how can we round the numeric value? > Example: 1.2 = 1.5, 1.7 = 2.0 Use the RND function..... =CEILING(A1,0.5) -- Regards Dave Hawley www.ozgrid.com "Salman Saeed" <Salman Saeed@discussions.microsoft.com> wrote in message news:F5460D85-6DEE-4EC5-8E83-A1A5E158966A@microsoft.com... > Kindly...

vlookup-Closest value
Dear Friends, How can I use Vlookup to give me the closest value greather than or equal to vlookup value.For example if my lookup value is 5 and I have 4.9 and 5.1,5.2 It chooses 5.1 and give me the corresponding value. Thank you, atatari wrote: > Dear Friends, > > How can I use Vlookup to give me the closest value greather than or equal to > vlookup value.For example if my lookup value is 5 and I have 4.9 and 5.1,5.2 > It chooses 5.1 and give me the corresponding value. > > Thank you, VLOOKUP(lookup_value,table_array,col_index_num,range_lookup) The default behavi...

The most occurence of a value in a column
I have 1 to 5 as values in a column. How can I find the number with the most occurrence in that column? Thanks, cpliu Hi =MODE(A1:A100) -- Regards Frank Kabel Frankfurt, Germany "cpliu" <chanciusliuDeleteThis@yahoo.com> schrieb im Newsbeitrag news:Xns959C8C47C309BchanciusliuDeleteThi@130.133.1.4... > I have 1 to 5 as values in a column. How can I find the number with the > most occurrence in that column? > > Thanks, > > cpliu Try: =INDEX(A1:A5,MATCH(MAX(COUNTIF(A1:A5,A1:A5)),COUNTIF (A1:A5,A1:A5),0)) Array-entered, meaning press ctrl/shift/enter. H...

Crystal XI will not show all possible values in a parameter field
Hello: We have a Crystal XI report that has one parameter value that is a "static" rather than "dynamic". It works fine and, when you type in a value upon refreshing the report, the data is correct. We made a copy of the report, because we want a second report where the parameter value is dynamic rather than static. We do not want a range, but we do want a parameter that will show all possible values on the left and allow you to pick and choose one or more of those values. For some reason, not all of the possible values are showing in this dynamic parameter field...

Selecting only some of the drop down options
I have a form set up that uses a query as a records source. I have 5 different drop downs to choose from with the criteria in the query set up as like below to link to the form >=[Forms]![Selected Criteria Form]![Year] By setting up this way, you need to select something from all 5 drop down lists for it to work. How would I set it up where I could select anywhere from 1 to 5 of the drop down options? Not necessarily. There is a technique you can use that will solve that problem; however, I need to know if the drop downs are on the form you are filtering, or are you making s...

reformulating question regarding maximum value
I had an hour ago put a question up named "find maximum", but I had not formulated my query fully, hence this query. In each row, I want to find the second highest value in that row, and then as output give the value of that cell in the first row. For example: 1 2 6 8 6 5 4 3 2 4 5 6 3 2 3 8 6 4 5 3 7 2 3 1 The second largest value in the second row is nr 6. It is in the fourht cell of that row. The fourth cell of the first row is the value 8. This should be the output for the second row. The second largest value in the third row is the number 6. It is in the first cell of th...

Automatic formatting of minimum/maximum value in a range.
I want that if I select a range of numbers the minimum or maximum should be selected by a single command How about cond. formatting? 1. Select the range. 2. Go to Format > Conditional Formatting 3. Select "Formula Is" and copy in this: =OR(INDIRECT("rc",0)=MAX(rng),INDIRECT("rc",0)=MIN(rng)) where "rng" is a defined name for your range. HTH Jason Atlanta, GA >-----Original Message----- >I want that if I select a range of numbers the minimum or maximum should be >selected by a single command >. > What do you want to do with t...

isv.config rollback to default value when publish new customization
dear expert, Anybody had idea for this problem?? "msnews.microsoft.com" <hattha9@hotmail.com> wrote in message news:eSkdJp7UFHA.3312@TK2MSFTNGP09.phx.gbl... > dear expert, > Anybody had idea for this problem?? > > > Yes, there is another copy of the ISV.config that gets copied on public - cant remember where it is. A search will find it, rename it and all will be fine for the next publish. I will try and find the exact location and post The file should be located in the c:\Program Files\Microsoft CRM\Tools\Config, or wherever you installed M...

Problem with draging a formula,one cell value fixed,trivial question
Hi. I have a value in cell A10. Then i have a formula in cell C1 which goes: (A1+B1)/A10. If I drag the formula down to cell C5 the formula for C2 will be (A2+B2)/A11, for C3 will be (A3+B3)/A12,....,for C5 will be (A5+B)/A14. I would like the formula to have the A10 parameter fixed so when i drag the formula down the A10 would always be A10(it wouldn't go up by 1). So the formula for C2 will be (A2+B2)/A10, for C3 will be (A3+B3)/A10,....,for C5 will be (A5+B5)/A10. Please help. Thanks, Marko make your original in C1 formula =(A1+B1)/A$10 then drag down. See help on absolute versus re...

Creating array from matrix with blank values
I have a matrix in the following format 1 X X X X X X X X X X X 3 X X X X X 4 X X X X X X X X where 'X' is a blank cell. I need to get the data in the form 1 3 4 Any suggestions? I tried a nested if statement but it doesn't work since there are more than 7 ifs. Andryll, If there is only one value in each row, then simply using =SUM(A1:L1) where A1:L1 is your top row, then copied down for two more rows, will give you your desired result. HTH, Bernie MS Excel MVP <Andryll.Davis@gmail.com> wrote in message news:1160141392.644344.173360@i3g2000cwc.googlegroups.com......