WSDL does not show correct return type information for C# web service


M

m4gnus

I have made a web service using C# and my problem is that the
auto-generated WSDL-file does not show the correct type information for
return parameters. It is desireable that it does because people who are
to use the web service must know what it returns and it would be nice
if they didn't have to ask me but instead just look in the WSDL-file.

The method public MailboxStatus[] GetMailboxStatus(string[]
extensions) returns a MailboxStatus[] which looks like this:
public class MailboxStatus
{
/// <summary>
/// The mailbox's id.
/// </summary>
private int id;

/// <summary>
/// The mailbox's user id.
/// </summary>
private int uid;

/// <summary>
/// The messages in the mailbox.
/// </summary>
private Message[] messages;
}

The 'id' and 'uid' are shown correctly in the WSDL but 'messages' is
not. Like this:
<GetMailboxStatusResponse xmlns="http://www.icepeak.se/webservices/">
<GetMailboxStatusResult>
<MailboxStatus>
<Id>int</Id>
<Uid>int</Uid>
<Messages>
<Message xsi:nil="true" />
<Message xsi:nil="true" />
</Messages>
</MailboxStatus>
</GetMailboxStatusResult>
</GetMailboxStatusResponse>


If I add [return:XmlArrayItem(typeof(Message))] above the
GetMailboxStatus method 'messages' is shown correctly but instead 'id'
and 'uid' are not, they are not shown at all actually. Like this:

<GetMailboxStatusResponse xmlns="http://www.icepeak.se/webservices/">
<GetMailboxStatusResult>
<Message>
<Id>int</Id>
<Status>int</Status>
<TimestampInUTC>dateTime</TimestampInUTC>
<LengthInSeconds>int</LengthInSeconds>
<ANumber>int</ANumber>
<FileFormat>string</FileFormat>
<Url>string</Url>
</Message>
</GetMailboxStatusResult>
</GetMailboxStatusResponse>


Any ideas on how to solve this so both 'id', 'uid' and 'messages' types
are shown in the auto-generated WSDL?

Looking forward to your helpful reponse
Thanks in advance
Magnus

ps. I hope it was correct to post this here even though it's about
something written in C#. If not, please inform me.
 
Ad

Advertisements

M

m4gnus

Thank you very much for responding to my question. It seems very few
knows about this because I've asked around a lot and no one had the
slighest idea.

However, I did what you suggested but Message is still shown as before
in the WSDL.
I added:
/// <summary>
/// The messages in the mailbox.
/// </summary>
[XmlArray(ElementName = "WhatEver_Like_Messages", IsNullable=false)]
[XmlArrayItem(Type = typeof(Message),
ElementName="WhatEver_Like_Message")]
private Message[] messages;
(let's refer to XmlArray.. by A)

and

[return: XmlArray(ElementName="WhatEver_Like_MessageBoxStatusArray",
IsNullable=false)]
[return: XmlArrayItem(typeof(MailboxStatus))]
public MailboxStatus[] GetMailboxStatus(string[] extensions)
(let's refer to XmlArray.. by B)

I seems very logical but still doesn't work...hmm
Did I misunderstand something?

If I comment out B, Message is shown correctly in the WSDL, but when I
have both A and B, Message is shown as:
<Messages>
<Message xsi:nil="true" />
<Message xsi:nil="true" />
</Messages>

In the HTTP POST section it looks like it should, but not in the SOAP
section.

Cheers
Magnus


Gaurav Vaish (www.EdujiniOnline.com) skrev:
/// <summary>
/// The messages in the mailbox.
/// </summary>
private Message[] messages;
}

Add attributes:
[XmlArray(ElementName = "WhatEver_Like_Messages", IsNullable=true/false)]
[XmlArrayItem(Type = typeof(Message), ElementName="WhatEver_Like_Message")]

to the 'messages' field.
If I add [return:XmlArrayItem(typeof(Message))] above the
GetMailboxStatus method 'messages' is shown correctly but instead 'id'
and 'uid' are not, they are not shown at all actually. Like this:

Because you've said that the items are are of type Message... and not
MailboxStatus.
It should have been:

[return: XmlArray(ElementName="WhatEver_Like_MessageBoxStatusArray",
IsNullable=true/false)]
[return: XmlArrayItem(typeof(MailboxStatus))]




--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujinionline.com
http://eduzine.edujinionline.com
-----------------------------------------
 

Top