473,385 Members | 1,766 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,385 software developers and data experts.

Problems making a string property mandatory

Hi,

I am developing a web service for a customer. The service has a method, that
returns an array of Forms. Each form has a Name property of Type String.

The customer wants the contract to specify, thath the name is mandatory and
not nullable. To reflect this, they want the xml in the wsdl (the Form part)
to look similar to this:

<xs:complexType name="Form">
<xs:sequence>
...
<xs:element minOccurs="1" maxOccurs="1" name="Name" nillable="false"
type="xs:string" />
...

So, minOccurs should be 1 and nillable should be false (or omitted), to
ensure the value is present and not null.

No matter how I go about this, however, I cannot make the wsdl generate the
desired values. I have tried to do contract-first development using WSCF from
thinktecture, and have the schema dictate the above values for minOccurs and
nillable, but this approach has not remedied the problem.

Is it at all possible to do what I want using .Net and Visual Studio 2005? I
hope my problem is described adequately, otherwise please request more
information. Any help is greatly appreciated.
May 22 '07 #1
15 1856
Hi,

Regarding on the webservice class property definition problem you
mentioned, here are some of my understanding and suggestion:

1. .NET webservice will always generate the xsd scheme for class property
as below:

** for value type(primitive types or struct), it will use minOccurs="1"
since value type will always be assigned a value(doesn't have null value
unless you use nullable type).

** for reference type(such as normal class), it will use minOccurs="0"
since value type will always support null value, the "string" type in your
case is just conform to this policy.

So far this rule is not changable in our custom code(attribute).

2. Also, XML XSD schema definition's element definition doesn't 100%
completely identical to .NET(or OO ) class/type definition. For example, if
you have the following xsd schema

<element minOccurs="1" ..../>

you can not find a reference type to mapping it since reference type always
support null reference value. I think you can consider define a wrapper
class(which inherit from ValueType ), property of such type will be
automatically generated as minOccurs="1" in XSD schema. However, you still
need to ensure that any sub property of reference type(such as string) has
been supplied a value in your own code.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

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


May 22 '07 #2
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:9C**********************************@microsof t.com...
Hi,

I am developing a web service for a customer. The service has a method,
that
returns an array of Forms. Each form has a Name property of Type String.

The customer wants the contract to specify, thath the name is mandatory
and
not nullable. To reflect this, they want the xml in the wsdl (the Form
part)
to look similar to this:

<xs:complexType name="Form">
<xs:sequence>
...
<xs:element minOccurs="1" maxOccurs="1" name="Name" nillable="false"
type="xs:string" />
...

So, minOccurs should be 1 and nillable should be false (or omitted), to
ensure the value is present and not null.

No matter how I go about this, however, I cannot make the wsdl generate
the
desired values. I have tried to do contract-first development using WSCF
from
thinktecture, and have the schema dictate the above values for minOccurs
and
nillable, but this approach has not remedied the problem.

Is it at all possible to do what I want using .Net and Visual Studio 2005?
I
hope my problem is described adequately, otherwise please request more
information. Any help is greatly appreciated.
You don't need to let .NET generate the WSDL for you. Create your own WSDL
(perhaps based on the one that .NET generates) and then use that.
--
John Saunders [MVP]
May 22 '07 #3
"John Saunders [MVP]" wrote:
[...]
You don't need to let .NET generate the WSDL for you. Create your own WSDL
(perhaps based on the one that .NET generates) and then use that.
--
John Saunders [MVP]
Hi John,

Thanks for your reply.

That's an interesting idea; can you point me in the right direction on where
to look for how I can use my own WSDL? I have already generated one using
contract-first techniques, and I would very much like to use that instead of
the .Net generated one.
May 23 '07 #4
Hi Steven,

Thank your for replying. It would seem creating a wrapper will just "nest"
the problem one level deeper, since the wrapper will still need a string
property/field, that will be generated "incorrectly" (for my present purpose)
in the xsd.

Is it possible to hook in to the wsdl generation process at some point to do
some post filtering of the output or generating the wsdl entirely by custom
code?

"Steven Cheng[MSFT]" wrote:
Hi,

Regarding on the webservice class property definition problem you
mentioned, here are some of my understanding and suggestion:

1. .NET webservice will always generate the xsd scheme for class property
as below:

** for value type(primitive types or struct), it will use minOccurs="1"
since value type will always be assigned a value(doesn't have null value
unless you use nullable type).

** for reference type(such as normal class), it will use minOccurs="0"
since value type will always support null value, the "string" type in your
case is just conform to this policy.

So far this rule is not changable in our custom code(attribute).

2. Also, XML XSD schema definition's element definition doesn't 100%
completely identical to .NET(or OO ) class/type definition. For example, if
you have the following xsd schema

<element minOccurs="1" ..../>

you can not find a reference type to mapping it since reference type always
support null reference value. I think you can consider define a wrapper
class(which inherit from ValueType ), property of such type will be
automatically generated as minOccurs="1" in XSD schema. However, you still
need to ensure that any sub property of reference type(such as string) has
been supplied a value in your own code.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights
May 23 '07 #5
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:CA**********************************@microsof t.com...
"John Saunders [MVP]" wrote:
[...]
>You don't need to let .NET generate the WSDL for you. Create your own
WSDL
(perhaps based on the one that .NET generates) and then use that.
--
John Saunders [MVP]
Hi John,

Thanks for your reply.

That's an interesting idea; can you point me in the right direction on
where
to look for how I can use my own WSDL? I have already generated one using
contract-first techniques, and I would very much like to use that instead
of
the .Net generated one.
Sorry, use it for what? Give it to your clients. Tell them to point to the
WSDL instead of using "?WSDL".
--
John Saunders [MVP]
May 23 '07 #6
I'm sorry, it seems I know to little about this to ask the right questions.

I just thought that if my client pointed to the Wsdl file, the web service
itself would still allow incorrect data (that will not validate against the
schema) in the Form object. Are you saying that's not an issue at all?

I would rather the check occurred via the schema, so I will not have to
check for validity on multiple levels. I would hate to have a situation where
changes needed to be reflected in more than one place (i.e. both in the Wsdl
and in the OO objects).

Thank you for your help.

/Mads Nielsen

"John Saunders [MVP]" wrote:
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:CA**********************************@microsof t.com...
"John Saunders [MVP]" wrote:
[...]
You don't need to let .NET generate the WSDL for you. Create your own
WSDL
(perhaps based on the one that .NET generates) and then use that.
--
John Saunders [MVP]
Hi John,

Thanks for your reply.

That's an interesting idea; can you point me in the right direction on
where
to look for how I can use my own WSDL? I have already generated one using
contract-first techniques, and I would very much like to use that instead
of
the .Net generated one.

Sorry, use it for what? Give it to your clients. Tell them to point to the
WSDL instead of using "?WSDL".
--
John Saunders [MVP]
May 24 '07 #7
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:78**********************************@microsof t.com...
I'm sorry, it seems I know to little about this to ask the right
questions.

I just thought that if my client pointed to the Wsdl file, the web service
itself would still allow incorrect data (that will not validate against
the
schema) in the Form object. Are you saying that's not an issue at all?

I would rather the check occurred via the schema, so I will not have to
check for validity on multiple levels. I would hate to have a situation
where
changes needed to be reflected in more than one place (i.e. both in the
Wsdl
and in the OO objects).
Oh, I see. Check out this article in MSDN. It's a bit advanced, but you may
be able to copy/paste the code: Web Services: Extend the ASP.NET WebMethod
Framework by Adding XML Schema Validation
(http://msdn.microsoft.com/msdnmag/is.../default.aspx).
--
John Saunders [MVP]
May 24 '07 #8
This is great stuff and will definitely solve my validation concerns, thanks
alot!

Do you know if there a similar hooks that I can use, so my service will
return the manually crafted Wsdl file when invoked with "?wsdl" instead of
the generated one?

/Mads Nielsen

"John Saunders [MVP]" wrote:
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:78**********************************@microsof t.com...
I'm sorry, it seems I know to little about this to ask the right
questions.

I just thought that if my client pointed to the Wsdl file, the web service
itself would still allow incorrect data (that will not validate against
the
schema) in the Form object. Are you saying that's not an issue at all?

I would rather the check occurred via the schema, so I will not have to
check for validity on multiple levels. I would hate to have a situation
where
changes needed to be reflected in more than one place (i.e. both in the
Wsdl
and in the OO objects).

Oh, I see. Check out this article in MSDN. It's a bit advanced, but you may
be able to copy/paste the code: Web Services: Extend the ASP.NET WebMethod
Framework by Adding XML Schema Validation
(http://msdn.microsoft.com/msdnmag/is.../default.aspx).
--
John Saunders [MVP]
May 24 '07 #9
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:33**********************************@microsof t.com...
This is great stuff and will definitely solve my validation concerns,
thanks
alot!

Do you know if there a similar hooks that I can use, so my service will
return the manually crafted Wsdl file when invoked with "?wsdl" instead of
the generated one?
I don't yet have a complete answer for that. I have to answer it for myself,
as well.

In the meantime, I'm going to suggest to you what I'm going to suggest for
my situation: put the .wsdl file "next to" the service. In addition to
http://server/Service.asmx, have http://server/Service.wsdl. You'll just
have to make sure that IIS is configured to pass the .wsdl extension to
ASP.NET, and you'll have to configure the HttpHandler to serve it up. I
forget the name of the correct handler, maybe FileHttpHandler or something?
--
John Saunders [MVP]
May 24 '07 #10
Thanks for the answer, I will try that.

/Mads Nielsen

"John Saunders [MVP]" wrote:
"Mads Nielsen" <Re*************@newsgroups.nospamwrote in message
news:33**********************************@microsof t.com...
This is great stuff and will definitely solve my validation concerns,
thanks
alot!

Do you know if there a similar hooks that I can use, so my service will
return the manually crafted Wsdl file when invoked with "?wsdl" instead of
the generated one?

I don't yet have a complete answer for that. I have to answer it for myself,
as well.

In the meantime, I'm going to suggest to you what I'm going to suggest for
my situation: put the .wsdl file "next to" the service. In addition to
http://server/Service.asmx, have http://server/Service.wsdl. You'll just
have to make sure that IIS is configured to pass the .wsdl extension to
ASP.NET, and you'll have to configure the HttpHandler to serve it up. I
forget the name of the correct handler, maybe FileHttpHandler or something?
--
John Saunders [MVP]
May 25 '07 #11
Hi,

For customize the ASP.NET autogenerated wsdl document, one way is to supply
a custom wsdl document completely authored by ourselves through the binding
setting:

http://pluralsight.com/blogs/craig/a.../15/17482.aspx

Here are some other information about other configuration about customize
ASP.NET webservice's WSDL generation:

#Configuring WSDL File Generation for ASP.NET Web Services
http://msdn2.microsoft.com/en-us/lib...76(vs.80).aspx
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 27 '07 #12
Hi Mads,

How are you doing on this issue, do you get any progress? Or does the
information about provide custom WSDL document in ASP.NET webservice in
ther other reply also helps some? If you still have anything need help,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
May 30 '07 #13
I am getting there. Currently I have created an HttpModule which handles
requests for ?wsdl and ?disco and redirects to the manually altered wsdl file.

I have added the following to web.config:
<appSettings>
<!--
Determines if ?wsdl for the service gets redirected to the maunally
edited .wsdl file.
If the setting is present specify all pages that get redirected
(separated by semicolon)
as value, e.g.: value="Service1.asmx;Service2.asmx;..."
-->
<add
key="RedirectWsdl"
value="DataExtract.asmx"/>
</appSettings>
[...]
<system.web>
<httpModules>
<add type="Resultmaker.Dia.Webservices.AsmxHelpModule,
Resultmaker.Dia.Webservices"
name="AsmxHelpModule" />
</httpModules>

I have then created the module as follows:

public class AsmxHelpModule : IHttpModule {
private AsmxHelpModule() {}
void Application_BeginRequest(object sender, System.EventArgs e) {
string requestPath = HttpContext.Current.Request.RawUrl;
requestPath = requestPath.Trim();
requestPath = requestPath.ToLower();
string setting = ConfigurationManager.AppSettings["RedirectWsdl"];
if (((setting != null) && (setting != ""))) {
setting = setting.ToLower();
string[] fileNames = setting.Split(';');
for (int i = 0; i != fileNames.Length; ++i) {
string fn = fileNames[i];
if (((requestPath.IndexOf((fn + "?wsdl")) 0)
|| (requestPath.IndexOf((fn + "?disco")) >
0))) {

HttpContext.Current.Server.Transfer("DataExtract.w sdl", false);
return;
}
}
}
}
public virtual void Init(HttpApplication app) {
app.BeginRequest += new
System.EventHandler(this.Application_BeginRequest) ;
}
[...]
}

I hope this may help others with similar problems.

/Mads Nielsen

"Steven Cheng[MSFT]" wrote:
Hi Mads,

How are you doing on this issue, do you get any progress? Or does the
information about provide custom WSDL document in ASP.NET webservice in
ther other reply also helps some? If you still have anything need help,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights
May 30 '07 #14
Thanks for your followup and share the result.

If you have interest, you can also have a look at the "WebServiceBinding"
approach for provide custom wsdl:

http://pluralsight.com/blogs/craig/a.../15/17482.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
May 31 '07 #15
Thanks Guys, I had the same issue and this post was helpful in fixing my
problem as well.

Cheers.

"Steven Cheng[MSFT]" wrote:
Thanks for your followup and share the result.

If you have interest, you can also have a look at the "WebServiceBinding"
approach for provide custom wsdl:

http://pluralsight.com/blogs/craig/a.../15/17482.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights
Aug 23 '07 #16

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

Similar topics

1
by: Phil Powell | last post by:
<? class ErrorMsgCollection { var $name; var $mandatory; var $emptyErr; var $maxLength; var $maxLengthErr; var $minLength; var $minLenghtErr;
4
by: MT | last post by:
Hi all, this sounds like an easy enough thing to do, but after spending 45 minutes searching google and various javascript sites I can't find out how to make a textfield (textbox or whatever you...
2
by: Lisa | last post by:
I have to work with an existing xml where there is a root element and all other elements are children of the root (in other words there is no nesting or hierarchy), e.g. <myroot> <A>adata</A>...
4
by: JC - home | last post by:
Hello.. I've been having some problems for a little while with this which I was sure I would beat...hmmm. Anyway, I have a form with two rich textboxes. One at the top which is to display a...
1
by: nate axtell | last post by:
In VB .Net I made a custom CheckBox column style (for the Datagrid control) that maps to two DataTable columns , one it uses for the Checked status and the other it uses for the Enabled status. I am...
3
by: Philip Wagenaar | last post by:
I created a Mustinherit class with two must override readonly properties: Public MustInherit Class RequestPart Public MustOverride ReadOnly Property Description() As Boolean Public MustOverride...
4
by: Ricardo | last post by:
Hi wizards, I have an object , this object generate a set of 9 random numbers. When I generate for example 10 object his 9 random numbers are equals. How can I make this 9 numbers are different...
2
by: karen987 | last post by:
Can someone please tell me how to alter this code if it needs altering, . thanks in advance. 1. The form keeps focusing on "username" and won't submit. The 2 username functions may be clashing?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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:
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...
0
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,...
0
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...

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.