W
William F. Kinsley
I'm trying to use complex types in a Web service as follows:
// In Some Util Library
[Serializable]
public class PatientFilter
{
....
}
[Serializable]
public class PatientCollection : IEnumerable
{
....
}
// In the webservice asmx.cs
[WebMethod]
public PatientCollection GetPatients(PatientFilter filter)
{
....
}
So this all works great, except that on the client side, after adding a web
reference, two things happen that aren't so good.
The first is that another PatientFilter class is auto generated in the
Reverence.cs in the WebReference namespace. This causes type problems
between the original PatientFilter class and the one in the Reference.cs. A
solution to this is to delete the auto generated class in Reference.cs and
everything works, but this is annoying as the class is constantly being
regenerated and I'm pretty sure there's a better way. When using a DataSet
class as a parameter, the auto generating tool does not make a new class in
Reference.cs. As best I can guess this is because the WSDL defines the
DataSet parameter as:
<s:complexType>
<s:sequence>
<s:element ref="s:schema" />
<s:any />
</s:sequence>
</s:complexType>
So my 1st question is how do I get my class to do the same, or similar thing
so that a new class does not get auto generated in Reference.cs
The second thing that happens that is annoying is that the GetPatients()
returns an object[] instead of a PatientCollection in the WebReference
class. Again, editing the Reference.cs and replacing the object[] return
parameter with PatientCollection fixes the problem and everything works.
The WSDL for this return value ends up being:
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetPatientsResult"
type="tns:ArrayOfAnyType" />
</s:sequence>
</s:complexType>
So my second question is how do I get the method to return a
PatientCollection instead of an ArrayOfAnyType automatically in the auto
generated class.
// In Some Util Library
[Serializable]
public class PatientFilter
{
....
}
[Serializable]
public class PatientCollection : IEnumerable
{
....
}
// In the webservice asmx.cs
[WebMethod]
public PatientCollection GetPatients(PatientFilter filter)
{
....
}
So this all works great, except that on the client side, after adding a web
reference, two things happen that aren't so good.
The first is that another PatientFilter class is auto generated in the
Reverence.cs in the WebReference namespace. This causes type problems
between the original PatientFilter class and the one in the Reference.cs. A
solution to this is to delete the auto generated class in Reference.cs and
everything works, but this is annoying as the class is constantly being
regenerated and I'm pretty sure there's a better way. When using a DataSet
class as a parameter, the auto generating tool does not make a new class in
Reference.cs. As best I can guess this is because the WSDL defines the
DataSet parameter as:
<s:complexType>
<s:sequence>
<s:element ref="s:schema" />
<s:any />
</s:sequence>
</s:complexType>
So my 1st question is how do I get my class to do the same, or similar thing
so that a new class does not get auto generated in Reference.cs
The second thing that happens that is annoying is that the GetPatients()
returns an object[] instead of a PatientCollection in the WebReference
class. Again, editing the Reference.cs and replacing the object[] return
parameter with PatientCollection fixes the problem and everything works.
The WSDL for this return value ends up being:
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetPatientsResult"
type="tns:ArrayOfAnyType" />
</s:sequence>
</s:complexType>
So my second question is how do I get the method to return a
PatientCollection instead of an ArrayOfAnyType automatically in the auto
generated class.