Mandatory WebMethod parameters

  • Thread starter Darren via .NET 247
  • Start date
D

Darren via .NET 247

Hi,

I have WebService (C#) with one WebMethod that takes 4 parameters, as below:

<s:element minOccurs="0" maxOccurs="1" name="requestedBy" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="submissionDateTime" type="s:dateTime" />
<s:element minOccurs="0" maxOccurs="1" name="orderReference" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="currentState" type="s:string" />

My problem is that I would like every one of these arguments to be mandatory when being call by the client i.e.

<s:element minOccurs="1" maxOccurs="1" name="requestedBy" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="submissionDateTime" type="s:dateTime" />
<s:element minOccurs="1" maxOccurs="1" name="orderReference" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="currentState" type="s:string" />

If it is not clear what my problem is from this then please let me know and I will try to clarify.

Any suggestions would be a great help.

Thanks,

Darren
 
D

Dino Chiesa [Microsoft]

Darren, you have a problem but you haven't said what the problem is.
Maybe I have an answer, but I'm not going to tell you. ???

Ok, I'm going to guess the problem. I am guessing that you are showing
WSDL snippets that have been generated, and they are not being generated the
way you want them to be.

Maybe you need to insert
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
in front of each of the string params that you want to be "mandatory".

I think you will get minOccurs=1 maxOccurs=1 from this.

What this will do is tell the webservices infrastructure that if it receives
a message that does not include all those elements, it should reject it.

This doesn't assure you that all requests received by your app logic will be
valid (depending on your application, of course). The issue is that strings
can be null in C#. So a request that totally omits an element like
<requestedBy>...</requestedBy> will be rejected by the runtime, but
something like <requestedBy nil="true"/> will be accepted by the ASMX
runtime, and then forwwarded to your app. Your app still needs to validate
the input to verify that strings that should be non-null are in fact
non-null.

Such things as xsd restrictions don't always reproduce nicely in C# / CLR,
so you need to do the validation yourself.


-Dino



Darren via .NET 247 said:
Hi,

I have WebService (C#) with one WebMethod that takes 4 parameters, as below:

<s:element minOccurs="0" maxOccurs="1" name="requestedBy" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="submissionDateTime" type="s:dateTime" />
<s:element minOccurs="0" maxOccurs="1" name="orderReference" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="currentState" type="s:string" />

My problem is that I would like every one of these arguments to be
mandatory when being call by the client i.e.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top