Hi there
I am trying to return an instance of a class from a web service that
contains a collection of instances of another class. I have three classes:
Person
MyEmails
MyEmail
Person is the 'base' class, which may contain an instance of
'MyEmails',which is essentially a collection of instances of 'MyEmail.' In
the code calling the web method the instance of the 'Person' class returned
is populated correctly, except that the properties/methods of my 'MyEmails'
class cannot be accessed. I just see the generic methods (ToString, Equals
etc). Am I missing something obvious?
The code for the file containing the three classes (in simplified form)
follow - thanks in advance if anyone can help.
Toby Mathews - 27 Oct 2003 19:20 GMT
Here's the code:
using System;
using System.Collections;
namespace Test.WebService
{
public class Person
{
private Test.WebService.MyEmails memEmails = new
Test.WebService.MyEmails();
public Test.WebService.MyEmails Emails {get {return memEmails;}set
{memEmails = value;}}
public Person()
{
}
}
public class MyEmails
{
ArrayList marEmails = new ArrayList();
public MyEmails()
{
}
public MyEmail this[int index]
{
get
{
Test.WebService.MyEmail remTmp = marEmails[index] as
Test.WebService.MyEmail;
return remTmp;
}
}
public void Add(string Email)
{
Test.WebService.MyEmail remTmp = new Test.WebService.MyEmail(Email);
marEmails.Add(remTmp);
}
public void Clear() {marEmails.Clear();}
public int Count {get {return marEmails.Count;}}
}
public class MyEmail
{
private string msEmail = "";
public MyEmail()
{
}
public MyEmail(string Email)
{
msEmail = Email;
}
public string Email {get {return msEmail;} set {msEmail = value;}}
}
}
Dino Chiesa [Microsoft] - 31 Oct 2003 21:22 GMT
Basically you need to:
- define your types in a shared assembly
- attach a targetNamespace attribute to each type
- deploy the assembly to both client and server
- when you generate the client-side proxy (using wsdl.exe or Add Web
Reference...), you have to modify it to reference the custom type.
- that's it.
Here's an old blog entry on the topic of custom types:
http://hoppersoft.com/Andy/commentview.aspx?guid=ABAF08B3-1ABD-4DAE-BE05-23B733FF3C5D
Here's an article on sharing types in webservices (somewhat relevant):
http://msdn.microsoft.com/library/en-us/dnservice/html/service07162002.asp
and a sort-of related KB article
http://support.microsoft.com/default.aspx?scid=kb;en-us;326790
-D