473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Returning a struct from a class method

Hi!

I'm building a web service with the purpose of administering the IIS service
on one of our servers. I'm trying to implement a method that can return
sites and their host headers. What I have so far is listed at the end of
this message. I'm using a struct to return some XML that can hold the
information that is returned. I'd like to put most of the content of the
"ListItems" method in a separate class file but I'm unable to figure out how
to write my code so that I get the struct returned - first to the WebMethod
and subsequently to the webservice. If I manage to get it sent to my web
service I'm also uncertain how to consume this information in my web
application... Strings are much simpler but I guess this is the right
approach?

Help is appreciated!!

Morten

public struct IISData
{
public String Name;
public System.Collections.Specialized.StringCollection ID;
}

[WebMethod]
public IISData[] ListItems()
{
int Number = GetNoOfSites();
IISData [] IISSites = null;
IISSites = new IISData[Number];
for (int i = 0; i < Number; i++)
{
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry direntry in root.Children)
{
if(direntry.SchemaClassName == "IIsWebServer")
{
string SiteName = (string) direntry.Invoke("Get", "ServerComment");
IISSites[i].Name = SiteName;
IISSites[i].ID = new
System.Collections.Specialized.StringCollection();
PropertyValueCollection pvc = direntry.Properties["ServerBindings"];
foreach (string header in pvc)
{
IISSites[i].ID.Add(header);
}
}
}
}
return IISSites;
}

public int GetNoOfSites()
{
int Number = 0;
DirectoryEntry root1 = new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry direntry1 in root1.Children)
{
if(direntry1.SchemaClassName == "IIsWebServer")
Number++;
}
return Number;
}
Nov 16 '05 #1
0 952

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Anthony | last post by:
Hello, I am writing a function that populates an array of pointers to strings. Both the number of strings in the array, and the lengths of the strings, are dynamic; in particular, the number of...
6
by: Generic Usenet Account | last post by:
Is it okay to return a local datastructure (something of type struct) from a function, as long as it does not have any pointer fields? I think it is a bad idea, but one of my colleagues does not...
9
by: thomson | last post by:
Hi all, Would you please explain me where will be the heap stored if it is declared inside the Class, As class is a reference type, so it gets stored on the heap, but struct is a value...
1
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two...
7
by: Kenneth Siewers Møller | last post by:
Hi there I know this probably have been addressed before, but I have an object that should contain the following Guid id String fName String lName Could I use a struct for that? I have read...
1
by: tawright915 | last post by:
I need to return a struct from another class. I set it up like this: public struct myData { public int mPKey; public String mOrgDate; public String mDataText; public myData(int mPKey, String...
1
by: stromhau | last post by:
Hi, I have made a few classes in c++. They somehow cooperate doing some 3d stuff. Basically it is a moving camera acting as a flight, i have placed a lot of objects around the scene together with...
17
by: djcredo | last post by:
Hey all, I want to return a pointer to a struct. Here is what I'lm trying to do: struct Position{ int x; int y; }; Position* GraphicTag::getRenderCentre(){
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.