Webservice does not generate WSDL element text as mandatory. 

Webservice does not generate WSDL element text as mandatory. 

  
Guys, I have a webservice method with three required input parameters: 2 of type Int and 1 text. By default the platform parameters in WS methods are set as Mandatory, and there is no option to change this in the parameter, because Is Mandatory property is not available for Web Services parameters.. The problem is that the WSDL that it generates comes this: 
 
<s: complexType> 
    <s: sequence> 
       <s: element minOccurs = "1" maxOccurs = "1" name = "EmpId" type = "s: int" /> 
       <s: element minOccurs = "1" maxOccurs = "1" name = "ActivityId" type = "s: int" /> 
       <s: element minOccurs = "0" maxOccurs = "1" name = "ActivityDescription" type = "s: string" /> 
    </ s: sequence> 
</ s: complexType> 
 
as you can see, its not putting string types as optional. Does anyone know how I can change this? It is a customer requirement that contract parameters be mandatory and I dont know how to change it.

Thanks
How about saving the wsdl in a text file, making necessary changes (i.e. setting minOccurs to 1) and loading it again by giving the url as local file system.
LIke this : file:///C:/abc/webservice.xml 
Solution
Hi André,

You currently can't control strings to have min-occurrs=1.

The reason that the Mandatory property does not exist in WebServices parameters is that (at least in the past) both .Net Framework and JAX-WS (in java) web service implementations did not respect correctly the mandatory specifications. By default they make nullable types as non-mandatory. So around version 5.1 or 6.0 we removed mandatory property on webservice inputs, since it did not work as expected.

Regards,
João Rosado
Solution
Thanks João Rosado. That explains a lot.

In .NET for example String has a non nullable default value, so it cannot satisfy the condition to get MinOccurs = 1Googling around I found the following:

 According to MSDN MinOccurs Attribute Binding Support , there are only 2 ways to get MinOccurs = 1.
  1. Value type with no default value or accompanying boolean field.

    Result: minOccurs value of output element is set to 1

  2. Reference type with an XmlElement attribute's IsNullable property set to true.

    Result: minOccurs value of output element is set to 1. In the element, the nillable attribute is also set to true.

A property of type string (unfortunately) always has a default value of

string.Empty

so it cannot ever have a null default value. This means we can't ever satisfy the first solution. The only way to generate a MinOccurs=1 for strings is to make the element nullable:

C#

[XmlElementAttribute(IsNullable = true)]
public string Item { ... }

VB

<XmlElement(IsNullable:=True)>
Public Item As String



Reference list:
StackOverflow Available at: http://stackoverflow.com/questions/3961112/how-to-make-a-dotnet-webservice-set-minoccurs-1-on-a-string-value (Accessed: 26 August 2014).



Hi,

Is still this the behavior for v9.0?

Do we have in OutSystems any simple way of setting the minOccurs = "?" value?
(we want to set 0 to Integer/Date/... and set 1 to string, I know that we can do a workaround setting the 'base' types inside strucs, and then apply the 'mandatory' to the struc, or setting all as strings, but this aren't exactly real solutions)

thanks,

Délio
Hi Délio,

Its sad, but I think its still the behavior for v9.0... and its not a platform limitation. The currently bad implementations for mandatory specifications on web services are the real limitation for this.
Hi André,

Thanks for the reply.
I think that it's a platform limitation not having a standardized solution.

It whould be nice to have available in OutSystems a simple overrive for he default WSDL generation (+- like it's available for 'OnBeforeRequest'/'OnAfterResponse' in REST, that's was a good simple ideia, that helps a lot), or a simple solution to set the default null values for the types/vars, and then let the developers treat the problem of mapping them to the non nullable types/vars in OutSystems.

If simpler solution is available, we wil go for one of the workarounds :(


thanks,

Délio


I understand and totally agree with you. The platform should have more flexibility for web services (edit the generated WSDL like you said would be nice), but for some reason we can't access this level of customization.

You can share it creating an "Idea" for this in the community and hope it be attended someday.

Tip: Sometimes the best workaround is not to create a complex solution to the problem, but try to change the problem, adapting it to your solution. if the "solution" is not working, try something new. 

Thanks for the info guys ... I ran into the same problem were I want to make a string mandatory ... But I can't :-(