Groups | Blog | Home
all groups > dotnet web services > july 2006 >

dotnet web services : Multiplt XmlElementAttribute for WebMethod parameter



Sek
7/14/2006 1:16:41 AM
Gurus,

I have a scenario in which two web methods take the same class/struct
as parameter.
The class/struct in turn has two members. The first member being used
by both methods remains as a common data member. The second member is a

"object" such that, it will contain custom data based on the method
being invoked. To put things clear, following is the class i am talking

about:


[XmlTypeAttribute(Namespace="http://xxx")]
public class MessageParams
{
[XmlElementAttribute("Credentials")]
public Credential cred;


[XmlElementAttribute("FirstMethodParam",
typeof(FirstMethodDataType))]
[XmlElementAttribute("SecondMethodParam",
typeof(SecondMethodDataType))]
public object Item;



}


Following are the web methods, i was mentioning:

[WebMethodAttribute()]
[SoapDocumentMethodAttribute(Use=SoapBindingUse.Literal,
ParameterStyle=SoapParameterStyle.Bare)]
[return: XmlElementAttribute("MessageReceipt", Namespace="http://xxx")]

public WebResp FirstMethod([XmlElementAttribute("Message")]
MessageParams Message)
{
return new object();



}


[WebMethodAttribute()]
[SoapDocumentMethodAttribute(Use=SoapBindingUse.Literal,
ParameterStyle=SoapParameterStyle.Bare)]
[return: XmlElementAttribute("MessageReceipt", Namespace="http://xxx")]

public WebResp SecondMethod([XmlElementAttribute("Message")]
MessageParams Message)
{
return new object();


}


When i build and run the webservice, the XML element for the second
member of "MessageParams" namely "Item" is not serialized and
therefore, doesn't appear in the web services test page. For ex:

Following is the result on the webservice test page. This is NOT the
expected result, as the "FirstMethodParam" element is missing below
"Credentials" element.
<soap:Body>
<MessageParams xmlns="http://xxx">
<Credentials>
<LoginName>string</LoginName>
<Password>string</Password>
<CallerUserID>string</CallerUserID>
</Credentials>
</MessageParams>
</soap:Body>


Following is the expected result, as "FirstMethodParam" is appearing
below "Credentials" element.
<soap:Body>
<MessageParams xmlns="http://XXX">
<Credentials>
<LoginName>string</LoginName>
<Password>string</Password>
<CallerUserID>string</CallerUserID>
</Credentials>
<FirstMethodParam>
<Source/>
<Destination/>
</FirstMethodParam>
</MessageParams>
</soap:Body>


Is this possible under webservices?


TIA.
Sek
olrt
7/15/2006 11:53:38 PM
[quoted text, click to view]

You should make your class IXmlSerializable (well I know it's poorly
documented in .NET Framework documentation libraries) and implement its
methods.

Olivier.
AddThis Social Bookmark Button