ASMX and data contract collections.

Feb 23, 2009 at 7:46 AM
Edited Feb 24, 2009 at 6:30 AM
Hi,

I created an ASMX web service with two operations, viz. GetUsers and GetUser. The GetUser returns a data type object User, which is fine, but the GetUsers operation is returning a GetUsersResult object instead of the UserCollection object from the datatypes. This GetUsersResult is returning the list of User objects but why is the generated name GetUsersResult instead of the datatype UserCollection?

My UsersResponse XSD Message is pointing to the UserCollection XSD.

<?xml version="1.0" encoding="utf-8" ?>
<
xs:schema targetNamespace="http://company.com/testing/tas/types" elementFormDefault="qualified" xmlns="http://company.com/testing/tas/types" xmlns:mstns=http://company.com/testing/tas/types xmlns:xs="http://www.w3.org/2001/XMLSchema">
<
xs:element name="UserElement" type="User" />
<
xs:complexType name="User" >
<
xs:sequence>
<
xs:element name="UserID" type="xs:int" nillable="false" />
<
xs:element name="Username" type="xs:string" nillable="false" />
<
xs:element name="Fullname" type="xs:string" nillable="false" />
<
xs:element name="Name" type="xs:string" nillable="false" />
<
xs:element name="Surname" type="xs:string" nillable="false" />
<
xs:element name="EmailAddress" type="xs:string" nillable="false" />
<
xs:element name="PhoneNumber" type="xs:string" nillable="false" />
<
xs:element name="CellNumber" type="xs:string" nillable="false" />
<
xs:element name="EmployeeNumber" type="xs:string" nillable="false" />
<
xs:element name="IsActive" type="xs:boolean" nillable="false" />
<
xs:element name="IsExternal" type="xs:boolean" nillable="false" />
</
xs:sequence>
</
xs:complexType>
<
xs:element name="UserCollectionElement" type="UserCollection" />
<
xs:complexType name="UserCollection">
<
xs:sequence>
<
xs:element name="User" type="User" nillable="false" />
</
xs:sequence>
</
xs:complexType>
</
xs:schema>

The auto-generated code for UserCollection datatype is as follows:

using

 

System;
using System.Xml.Serialization;
namespace TAS.Svc.ASMX.DataTypes

 

{

 

 

/// <summary>
/// Data Contract Class - UserCollection
/// </summary>

 

 

 

[

Serializable]
[
XmlType(AnonymousType=true, Namespace = http://company.com/testing/tas/types)]
[
XmlRoot(Namespace = "http://company.com/testing/tas/types", IsNullable = false)]

 

 

 

 

public partial class UserCollection : System.Collections.Generic.List<User>
{
}
}

 

 

 

I got a UserCollection data contract collection  object in my data contract model. Am I doing this correctly? Why is the return type name as GetUsersResult instead of UserCollection?

Thanks,
JK.

 

 




 

 

 

Feb 23, 2009 at 8:01 AM
The service implementation is as follows:

 

/// <summary>
/// Gets all users from the system.
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>

 

 

public override TAS.Svc.ASMX.DataTypes.UserCollection GetUsers( UsersRequest request )
{
TAS.Svc.ASMX.DataTypes.
UserCollection userCollectionDataType;
TAS.Svc.ASMX.BusinessEntities.
UserCollection userCollectionEntity;
TAS.Svc.ASMX.BusinessLogic.
UserBAL userBAL = new TAS.Svc.ASMX.BusinessLogic.UserBAL();

 

 

try
{
userCollectionEntity = userBAL.GetUsers();
userCollectionDataType =
TranslateBetweenUserCollectionAndUserCollection.TranslateUserCollectionToUserCollection( userCollectionEntity );
return userCollectionDataType;
}
catch ( Exception ex )
{
throw ex;
}
finally
{
userCollectionEntity =
null;
userBAL =
null;
}
}

 

Developer
Feb 23, 2009 at 2:44 PM
The GetUsersResult is being generated in the client proxy?
If that the case, the it may be because that's the way that proxy gen will get a serialized collection from the wire.