Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / October 2003

Tip: Looking for answers? Try searching our database.

Returning my object(s) from web service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Toby Mathews - 27 Oct 2003 19:18 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.