简体   繁体   English

为什么c#不会因为在架构中使用xs:选项而在visual studio中使用add by service reference来创建来自wsdl的代码?

[英]Why would c# not create code from wsdl using add by service reference in visual studio just because of a xs:choice in the schema?

We created a soap server using php and few of the functions give a varying outcome in terms of the xml elements depending on the arguments passed through. 我们使用php创建了一个soap服务器,根据传递的参数,很少有函数根据xml元素给出不同的结果。

To explain further, a function takes in argument a and depending on the data received it can return either of the two different arrays(complextype) with distinct number of child elements. 为了进一步解释,函数接受参数a并且根据接收到的数据,它可以返回具有不同数量的子元素的两个不同数组(complextype)中的任何一个。

eg 例如

   if a =9 then outcome is array/struct ,,,, 
   a[delta]=20 ,,, 
   a[sigma]=yellow 

   if a =3  ,
   a[aTotallyDifferentBallgame]=Omaha ,,,
   a[t]=1 ,,,
   a[theNumberOfElementsCanVary]=yup

In order to explain this possible variance we utilized choice in the schema, thereby trying to intimate that the outcome can be any single element within choice be it simple or complextype. 为了解释这种可能的差异,我们在模式中使用了选择 ,从而试图暗示结果可以是选择中的任何单个元素,无论是简单类型还是复杂类型。

Now theoretically it sounds logical and it works fine with php's soap client but WHEN we tried to use the add Service Reference feature of the visual studio in a form application ; 现在理论上它听起来合乎逻辑,它可以与php的soap客户端一起工作,但是当我们尝试在表单应用程序中使用visual studio的添加服务引用功能时; the application failed to create code for it citing that the use of xs:choice is not allowed for some unfathomable reasons. 应用程序无法为其创建代码,因为某些不可理解的原因不允许使用xs:choice

Now what I would really like to know is what changes do I need to make to my wsdl or soap server to make this work. 现在我真正想知道的是我需要对我的wsdl或soap服务器进行哪些更改才能使其工作。 We thought a work around was by fixing the outcome to only one possible scenario and utilizing a completely different function to determine the outcome of the other thereby abstaining from use of choice but frankly this seems too redundant and weird. 我们认为解决方法是将结果仅限于一种可能的情况,并利用完全不同的功能来确定对方的结果,从而避免使用选择,但坦率地说,这似乎过于冗余和怪异。

Is there anything I have missed? 有什么我错过了吗? Please let me know any ideas you have. 请让我知道您的任何想法。 Thanks! 谢谢!

The create service reference machinery tries to map the schema to C# classes, and there is no structure in a C# class corresponding to a choice in the schema - a class cannot have a value for either one property or another one but not for both. 创建服务引用机制尝试将模式映射到C#类,并且C#类中没有与模式中的choice对应的结构 - 类不能为一个属性或另一个属性赋值,但对两者都不具有值。

My suggestion would be to replace choice with sequences of optional elements, the corresponding C# class will have properties for each of the elements - and only one of them will have a value, the other will be null , because the PHP service returns a value for only one of them at a time. 我的建议是用可选元素序列替换choice ,相应的C#类将具有每个元素的属性 - 并且其中只有一个将具有值,另一个将为null ,因为PHP服务返回一个值一次只有一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM