Marking an object for inclusion in WSDL

T

Thomas Koch

Hi - does anyone know if it is possible to single out an object for
inclusion in the WSDL of a Web Service?

I have a .asmx file with an associated code-behind file. The code-behind
file has a method:

[WebMethod]
public object[] MyMethod(C1 c1, C2 c2)

The return type is object[] due to the fact that object of differing types
(C3 and C4) can be returned. The types of these objects are all available in
the project.

Now, the WSDL tool does not include the types of the returned objects C3 and
C4, because their types are not explicitly present in the method signature.

My current workaround is to create a dummy web method that contains all the
types in the argument list like this:

[WebMethod]
public void DontCallMe(C1 c1, C2 c2, C3 c3, C4 c4)

which I think is a hack.

I'd be cool if I could do something like this:
[SOAPObject]
public class C3 { ... }

which would cause the object to be included in the WSDL.


Any help would be appreciated.

Regards
Thomas Koch
 
D

Dino Chiesa [Microsoft]

You can use the XmlInclude attribute to do what you want, I think.

[WebMethod(Description="Returns an ArrayList with typed members")]
[System.Xml.Serialization.XmlInclude(typeof(CEmployee))]
[System.Xml.Serialization.XmlInclude(typeof(CDeptManager))]
[System.Xml.Serialization.XmlInclude(typeof(Thing))]

[return:System.Xml.Serialization.XmlArrayItem("Emp",Type=typeof(CEmployee))]

[return:System.Xml.Serialization.XmlArrayItem("Mgr",Type=typeof(CDeptManager
))]
[return:System.Xml.Serialization.XmlArrayItem("Thing",Type=typeof(Thing))]
[return:System.Xml.Serialization.XmlRoot("TypedList",
Namespace="http://something.org/2003/10/types")]
public System.Collections.ArrayList GetList_ArrayList_Typed()
{
System.Collections.ArrayList list= new System.Collections.ArrayList ();
list.Add(new CEmployee());
list.Add(new CManager());
list.Add(new Thing());
return list;
}



References:

XmlInclude
http://msdn.microsoft.com/library/e...erializationXmlIncludeAttributeClassTopic.asp


-Dino
 
T

Thomas Koch

Hi Dino - that solved my problem, thanks a lot. :)

A few questions: Could you point me to a place where the [return: ... ]
prefix is explained. I've noticed a similar syntax used in the AssemblyInfo
files, which is using [assembly: ....]

I have a gut feeling for the meaning of the attribute prefix, but I would
like to read some specification on attribute prefixes in general.


Apparently I only need to insert XmlInclude attributes for the types in my
return list for them to be included in my WSDL, but I assume that the extra
attributes will make the return list strongly typed in the WSDL, right?


Regards
Thomas






Dino Chiesa said:
You can use the XmlInclude attribute to do what you want, I think.

[WebMethod(Description="Returns an ArrayList with typed members")]
[System.Xml.Serialization.XmlInclude(typeof(CEmployee))]
[System.Xml.Serialization.XmlInclude(typeof(CDeptManager))]
[System.Xml.Serialization.XmlInclude(typeof(Thing))]

[return:System.Xml.Serialization.XmlArrayItem("Emp",Type=typeof(CEmployee))][return:System.Xml.Serialization.XmlArrayItem("Mgr",Type=typeof(CDeptManager
[return:System.Xml.Serialization.XmlArrayItem("Thing",Type=typeof(Thing))]
[return:System.Xml.Serialization.XmlRoot("TypedList",
Namespace="http://something.org/2003/10/types")]
public System.Collections.ArrayList GetList_ArrayList_Typed()
{
System.Collections.ArrayList list= new System.Collections.ArrayList ();
list.Add(new CEmployee());
list.Add(new CManager());
list.Add(new Thing());
return list;
}



References:

XmlInclude
http://msdn.microsoft.com/library/e...erializationXmlIncludeAttributeClassTopic.asp


-Dino



Thomas Koch said:
Hi - does anyone know if it is possible to single out an object for
inclusion in the WSDL of a Web Service?

I have a .asmx file with an associated code-behind file. The code-behind
file has a method:

[WebMethod]
public object[] MyMethod(C1 c1, C2 c2)

The return type is object[] due to the fact that object of differing types
(C3 and C4) can be returned. The types of these objects are all
available
in
the project.

Now, the WSDL tool does not include the types of the returned objects C3 and
C4, because their types are not explicitly present in the method signature.

My current workaround is to create a dummy web method that contains all the
types in the argument list like this:

[WebMethod]
public void DontCallMe(C1 c1, C2 c2, C3 c3, C4 c4)

which I think is a hack.

I'd be cool if I could do something like this:
[SOAPObject]
public class C3 { ... }

which would cause the object to be included in the WSDL.


Any help would be appreciated.

Regards
Thomas Koch
 
D

Dino Chiesa [Microsoft]

Thomas Koch said:
Hi Dino - that solved my problem, thanks a lot. :)

A few questions: Could you point me to a place where the [return: ... ]
prefix is explained. I've noticed a similar syntax used in the AssemblyInfo
files, which is using [assembly: ....]
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconxmlserializationwithwebservices.asp


I have a gut feeling for the meaning of the attribute prefix, but I would
like to read some specification on attribute prefixes in general.

What you refer to is called the "Attribute Target".

I found this in the C# language specification:
http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_17_4_1.asp

It talks about AttributeUsage as a reserved attribute, and AttributeTarget
being one of the elements of AttributeUsage. Aside from assembly and
return value, there are other attribute targets. I don't believe you can
create your own AttributeTargets, but I do not know.
Apparently I only need to insert XmlInclude attributes for the types in my
return list for them to be included in my WSDL, but I assume that the extra
attributes will make the return list strongly typed in the WSDL, right?

with XmlArrayItem, you get to name the elements according to the serialized
type.

-Dino
 
T

Thomas Koch

Cool - thanks!

Thomas


Dino Chiesa said:
Thomas Koch said:
Hi Dino - that solved my problem, thanks a lot. :)

A few questions: Could you point me to a place where the [return: ... ]
prefix is explained. I've noticed a similar syntax used in the AssemblyInfo
files, which is using [assembly: ....]
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconxmlserializationwithwebservices.asp
I have a gut feeling for the meaning of the attribute prefix, but I would
like to read some specification on attribute prefixes in general.

What you refer to is called the "Attribute Target".

I found this in the C# language specification:
http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_17_4_1.asp

It talks about AttributeUsage as a reserved attribute, and AttributeTarget
being one of the elements of AttributeUsage. Aside from assembly and
return value, there are other attribute targets. I don't believe you can
create your own AttributeTargets, but I do not know.
Apparently I only need to insert XmlInclude attributes for the types in my
return list for them to be included in my WSDL, but I assume that the extra
attributes will make the return list strongly typed in the WSDL, right?

with XmlArrayItem, you get to name the elements according to the serialized
type.

-Dino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top