473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

optional fields in web service structures

Hi,
I've created a web service which uses a structure that I've defined. This
structure contains a string and a DateTime. When the WSDL is created the
string field is assigned a minoccurs of 0, while the DateTime field is
assigned a minoccurs of 1. How can I control the multiplicity of the field?
More specifically, I'd like to state that the DateTime field is optional
(minoccurs 0).
Thanks,
Zohar.
Nov 7 '06 #1
8 4580
"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:30**********************************@microsof t.com...
Hi,
I've created a web service which uses a structure that I've defined. This
structure contains a string and a DateTime. When the WSDL is created the
string field is assigned a minoccurs of 0, while the DateTime field is
assigned a minoccurs of 1. How can I control the multiplicity of the
field?
More specifically, I'd like to state that the DateTime field is optional
(minoccurs 0).
Of course, if you created your own WSDL instead of letting .NET do it for
you, you could set whatever multiplicity you like.

John
Nov 7 '06 #2
Of course, but I'm looking for a way to do it "right", from the class
definition.
Thanks.

"John Saunders" wrote:
"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:30**********************************@microsof t.com...
Hi,
I've created a web service which uses a structure that I've defined. This
structure contains a string and a DateTime. When the WSDL is created the
string field is assigned a minoccurs of 0, while the DateTime field is
assigned a minoccurs of 1. How can I control the multiplicity of the
field?
More specifically, I'd like to state that the DateTime field is optional
(minoccurs 0).

Of course, if you created your own WSDL instead of letting .NET do it for
you, you could set whatever multiplicity you like.

John
Nov 7 '06 #3
"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
Of course, but I'm looking for a way to do it "right", from the class
definition.
In my opinion (and in the opinion of many others), the "right" way to do it
is to start with the WSDL file (the "contract"), and to create the class
definition to match it. The WSDL file is the "contract" which you are
promising to implement - the class definition is not.

John
Nov 7 '06 #4
But this contract is written in a syntax which is very difficult for people
to read, it looks more of a "machine" thing. + all framworks (Axis, .NET...)
support doing it both ways (WSDl -code, code -WSDL), which suggests that
this is a "valid" option.
I suspect my issue has something to do with the type of the fields I
serialize. DateTime is a struct (hence a value type), while string is a
class (hence a reference type). Value types cannot be null (same way as an
'int' cannot), so it's minoccurs is 1...
Any idea how I can solve this?
"John Saunders" wrote:
"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
Of course, but I'm looking for a way to do it "right", from the class
definition.

In my opinion (and in the opinion of many others), the "right" way to do it
is to start with the WSDL file (the "contract"), and to create the class
definition to match it. The WSDL file is the "contract" which you are
promising to implement - the class definition is not.

John
Nov 8 '06 #5

"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
But this contract is written in a syntax which is very difficult for
people
to read, it looks more of a "machine" thing. + all framworks (Axis,
.NET...)
support doing it both ways (WSDl -code, code -WSDL), which suggests
that
this is a "valid" option.
I suspect my issue has something to do with the type of the fields I
serialize. DateTime is a struct (hence a value type), while string is a
class (hence a reference type). Value types cannot be null (same way as an
'int' cannot), so it's minoccurs is 1...
Any idea how I can solve this?
"John Saunders" wrote:
>"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:50**********************************@microso ft.com...
Of course, but I'm looking for a way to do it "right", from the class
definition.

In my opinion (and in the opinion of many others), the "right" way to do
it
is to start with the WSDL file (the "contract"), and to create the class
definition to match it. The WSDL file is the "contract" which you are
promising to implement - the class definition is not.

John

Nov 8 '06 #6
"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
But this contract is written in a syntax which is very difficult for
people
to read, it looks more of a "machine" thing.
That's good, since it's machines which consume the web service, not people.
>+ all framworks (Axis, .NET...)
support doing it both ways (WSDl -code, code -WSDL), which suggests
that
this is a "valid" option.
It's a valid option, in my opinion not a good option, except for simple web
services or those which are not important. If you don't mind the idea that
changing your server code slightly may change the contract, then go ahead.
I suspect my issue has something to do with the type of the fields I
serialize. DateTime is a struct (hence a value type), while string is a
class (hence a reference type). Value types cannot be null (same way as an
'int' cannot), so it's minoccurs is 1...
Any idea how I can solve this?
No, I don't. You're making my point. Your contract varies based on the
decisions that Microsoft .NET is making, not based on the decisions that
_you_ are making. You've already decided what your schema should look like;
you're now trying to figure out how to convince .NET to produce that schema
for you.

I say, produce it yourself and take responsibility for it.

John
Nov 8 '06 #7
I agree, I just want to know how this can be done in .NET (maybe for next time)

"John Saunders" wrote:
"Zohar" <Zo***@discussions.microsoft.comwrote in message
news:54**********************************@microsof t.com...
But this contract is written in a syntax which is very difficult for
people
to read, it looks more of a "machine" thing.

That's good, since it's machines which consume the web service, not people.
+ all framworks (Axis, .NET...)
support doing it both ways (WSDl -code, code -WSDL), which suggests
that
this is a "valid" option.

It's a valid option, in my opinion not a good option, except for simple web
services or those which are not important. If you don't mind the idea that
changing your server code slightly may change the contract, then go ahead.
I suspect my issue has something to do with the type of the fields I
serialize. DateTime is a struct (hence a value type), while string is a
class (hence a reference type). Value types cannot be null (same way as an
'int' cannot), so it's minoccurs is 1...
Any idea how I can solve this?

No, I don't. You're making my point. Your contract varies based on the
decisions that Microsoft .NET is making, not based on the decisions that
_you_ are making. You've already decided what your schema should look like;
you're now trying to figure out how to convince .NET to produce that schema
for you.

I say, produce it yourself and take responsibility for it.

John
Nov 8 '06 #8
Ron
In addition to what John mentioned on contract-first, you can at least define
the messages that go in and out of the service using XSD, and then xsd.exe to
generate the classes to work with. Doing this, you can specify in the message
that the particular dateTime element is not required with minOccurs = 0.

I did the following to demonstrate this:

Add a new .xsd file to the project.
Create a new element: MyTimeStamp
Add an element to that: CreateDateTime of dateTime type, minOccurs = 0

<xs:element name="MyTimeStamp">
<xs:complexType>
<xs:sequence>
<xs:element name="CreateDateTime" minOccurs="0" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Then used XSDObjectGenVSAddIn to generate the class file for that schema.
xsd.exe would work as well.

Anyways, the resulting code is this:

[XmlRoot(ElementName="MyTimeStamp",Namespace=Declar ations.SchemaVersion,IsNullable=false),Serializabl e]
public class MyTimeStamp
{

[XmlElement(ElementName="CreateDateTime",IsNullable =false,Form=XmlSchemaForm.Qualified,DataType="date Time",Namespace=Declarations.SchemaVersion)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public DateTime __CreateDateTime;

[XmlIgnore]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public bool __CreateDateTimeSpecified;

[XmlIgnore]
public DateTime CreateDateTime
{
get { return __CreateDateTime; }
set { __CreateDateTime = value; __CreateDateTimeSpecified = true; }
}

[XmlIgnore]
public DateTime CreateDateTimeUtc
{
get { return __CreateDateTime.ToUniversalTime(); }
set { __CreateDateTime = value.ToLocalTime(); __CreateDateTimeSpecified =
true; }
}

public MyTimeStamp()
{
__CreateDateTime = DateTime.Now;
}
}

You may be able to glean enough info to add some attributes to your datetime
field to get the desired result, however it's not apparent from the
attributes how that's achieved.

Anyways, I had a simple webmethod to return an instance of MyTimeStamp:

public MyTimeStamp Get()
{
return new MyTimeStamp();
}

note the CreateDateTime field is not specified. The resulting WSDL is
minOccurs = 0 for that field, and the sample XML response is this:

<MyTimeStamp xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/XMLSchema.xsd" />

No CreateDateTime in there cause it's optional, which is what you want.

By defining at least the message contracts in Xml Schema you can better
predict the results.

Ron

"Zohar" wrote:
Hi,
I've created a web service which uses a structure that I've defined. This
structure contains a string and a DateTime. When the WSDL is created the
string field is assigned a minoccurs of 0, while the DateTime field is
assigned a minoccurs of 1. How can I control the multiplicity of the field?
More specifically, I'd like to state that the DateTime field is optional
(minoccurs 0).
Thanks,
Zohar.
Nov 18 '06 #9

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

Similar topics

1
by: Ole S. Pedersen | last post by:
I have two tables: eg. a person-table (no nulls allowed), with an id and so on, and a person_course table (an intermediate table in a many-to many relationship between person table and courses...
1
by: MIchael McDowell | last post by:
Anyidea how this might be done using and XML Web Service and the XMLSerialzation class? A pointer to an online example would be deeply appreciated. Thankyou in advance, Michael McD
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
9
by: Stu | last post by:
Hi, I have a web service that does database access and calculations However it keeps falling over becuase its not multi threaded and each call to it is not in its own space!! I dont want to use...
1
by: Le Tubs | last post by:
Hi I am wondering if anybody has come accross this problem before, basically I have to validate a xml schema (not the data, this is done at a later stage). The only problem is that there are...
2
by: Oenone | last post by:
In our applications, we use the special value of DateTime.MinValue to represent "null dates" throughout all our code. We recently ran into an issue where we wanted an optional date parameter for a...
7
by: Sam Shrefler | last post by:
I'm working on creating a WebService / WebMethod to receive a record in real time from another system. The record contains about 20 fields. 10 of which aren't required. I was planning on just...
1
by: Glenn | last post by:
I am writing a Web Service in C# ASP.NET 2.0 that takes two optional parameters. One is an int and the other is a string. Below is the definition of the Web Method: public...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.