I have been experimenting with .Net web services for a while and have a few
questions about the schema in the automatically generated WSDL file, and
whether its content can be manipulated programatically.
First of all, I created several very simple test methods in my web service:
<WebMethod()> _
Public Function TestString(ByVal test As String) As String
Return "The value passed was " + test
End Function
<WebMethod()> _
Public Function TestInteger(ByVal test As Integer) As String
Return "The value passed was " + CStr(test)
End Function
When I look at the schema that was generated for these methods, I find the
following:
<s:element name="TestString">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="test" type="s:string"
/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="TestInteger">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="test" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
My question is - why did it specify a minOccurs of 0 for TestString, making
the argument optional, but specified a minOccurs of 1 for TestInteger? If a
method takes an argument, why is it making it optional for strings? Is it
possible to specify that a minOccurs of 1 should be used somewhere in code?
Also, if you want to validate against a custom schema type, say for a social
security number, how would you incorporate that into the automatically
generated WSDL file/schema? I read the article about customizing the
generation of service descriptions at
http://msdn2.microsoft.com/en-us/library/f9hatst6.aspx
but am not clear if the functionality they demonstrate can be used to do
what I want to do.
If it turns out that I cannot get what I want out of the automatically
generated WSDL/schema file, how could I then substitute my own file without
it being overwritten by the one being generated automatically?
Thanks,
Steve C.
John Saunders - 11 Oct 2006 18:51 GMT
>I have been experimenting with .Net web services for a while and have a few
> questions about the schema in the automatically generated WSDL file, and
[quoted text clipped - 56 lines]
> without
> it being overwritten by the one being generated automatically?
Steve,
The WSDL is only generated automatically if you allow it to be. If you use:
<webServices>
<protocols>
<remove name="Documentation"></remove>
</protocols>
</webServices>
in your web.config, then service.asmx?WSDL will not return a generated WSDL.
You can then host your WSDL wherever you like, or not at all.
As to the minOccurs="0", this is only a guess, but, as a reference type,
your string could be ommitted by returning null. In terms of XML Schema,
null is not a valid string. One way to represent it would be for it to be
absent entirely.
John
SteveChamp - 11 Oct 2006 22:55 GMT
John,
Thanks very much for the info. I may end up having to build my own WSDL from
scratch.
Steve C.