使字符串属性成为必需的问题 [英] Problems making a string property mandatory

查看:74
本文介绍了使字符串属性成为必需的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在为客户开发一项网络服务。该服务有一个方法,

返回一个Forms数组。每个表单都有一个Type属性,类型为String。


客户希望合同指定,名称是强制性的,

不可为空。为了反映这一点,他们希望wsdl中的xml(表单部分)

看起来与此类似:


< xs:complexType name =" ;表格">

< xs:sequence>

...

< xs:element minOccurs =" 1" maxOccurs的= QUOT 1 QUOT;命名= QUOT;姓名" nillable =" false"

type =" xs:string" />

...


因此,minOccurs应为1且nillable应为false(或省略),以

确保该值存在且不为空。


无论我如何处理这个问题,我都无法使wsdl生成

所需的值。我试图使用来自

thinktecture的WSCF进行契约优先开发,并且让架构规定minOccurs的上述值和

nillable,但这种方法还没有解决问题。


是否可以使用.Net和Visual Studio 2005做我想做的事情?我希望我的问题得到充分描述,否则请求更多

信息。非常感谢任何帮助。

解决方案




关于webservice类属性定义问题你

提到,以下是我的一些理解和建议:


1. .NET webservice将始终为类属性生成xsd方案

如下:


**对于值类型(原始类型或结构),它将使用minOccurs =" 1"

自值类型将永远被赋予一个值(没有空值

,除非你使用可空类型)。


**作为参考类型(例如正常因为值类型将始终支持空值,所以它将使用minOccurs =" 0"

,string键入你的

案例就是符合这个政策。


到目前为止,这条规则在我们的自定义代码(属性)中不可更改。


2.此外,XML XSD架构定义'的元素定义不是100%

与.NET(或OO)类/类型定义完全相同。例如,如果

你有以下xsd模式


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


你找不到引用它的引用类型,因为引用类型总是

支持空引用值。我认为你可以考虑定义一个包装器

类(继承自ValueType),这种类型的属性将自动生成为minOccurs =" 1"在XSD架构中。但是,你仍然需要确保引用类型的任何子属性(例如字符串)已经在你自己的代码中提供了一个值。
< br $> b $ b真诚的,


Steven Cheng


Microsoft MSDN在线支持主管


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


通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx


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


此帖子按原样提供。没有保证,也没有赋予任何权利。



" Mads Nielsen" < Re ************* @ newsgroups.nospamwrote in message

news:9C ***************** ***************** @ microsof t.com ...




我正在为客户开发Web服务。该服务有一个方法,



返回一个表格数组。每个表单都有一个Name属性Type String。


客户希望合同指定,名称是强制性的



不可空。为了反映这一点,他们希望wsdl中的xml(表格

部分)

看起来类似于:


< xs:complexType name =" Form">

< xs:sequence>

...

< xs: element minOccurs =" 1" maxOccurs的= QUOT 1 QUOT;命名= QUOT;姓名" nillable =" false"

type =" xs:string" />

...


因此,minOccurs应为1且nillable应为false(或省略),以

确保该值存在且不为空。


无论我怎么做,但是,我无法使wsdl生成



期望值。我已经尝试使用WSCF来进行契约优先开发

thinktecture的
,并且让架构规定minOccurs的上述值



nillable,但这种方法并没有解决问题。


是否可以使用.Net和Visual Studio 2005做我想做的事情?



希望我的问题得到充分描述,否则请求更多

信息。任何帮助是极大的赞赏。



你不需要让.NET为你生成WSDL。创建自己的WSDL

(可能基于.NET生成的那个),然后使用它。

-

John Saunders [MVP ]


" John Saunders [MVP]"写道:

[...]


你不需要让.NET为你生成WSDL。创建自己的WSDL

(可能基于.NET生成的那个),然后使用它。

-

John Saunders [MVP ]



嗨约翰,


感谢您的回复。


那个这是一个有趣的想法;你能指点我在正确的方向上寻找我如何使用自己的WSDL吗?我已经使用

契约优先技术生成了一个,我非常希望使用它来代替

.Net生成的技术。


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.

解决方案

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.



"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]


"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.


这篇关于使字符串属性成为必需的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆