Solved

How to return a 'struct' from a web service

Posted on 2006-10-27
4
281 Views
Last Modified: 2006-11-18
I have a need to return a struct from my web service to the calling C# Windows app... how do I do this?  The struct looks like this:

    private struct isbnAndPrices
    {
        string isbn;
        decimal[] prices;
    }
    isbnAndPrices retValue;


What should the return statement look like?  Also, when defining the public method, how do I indicate the return type is a struct?
0
Comment
Question by:rmmarsh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
andrewjmears earned 500 total points
ID: 17824336
I think you should make the struct public and make its members public. You don't need to do anything special to return a struct...

            public struct isbnAndPrices
            {
                  public string isbn;
                  public decimal[] prices;
            }

            [WebMethod]
            public isbnAndPrices getMyStruct()
            {
                  isbnAndPrices retValue = new isbnAndPrices();
                  retValue.isbn = "test_isbn";
                  retValue.prices = new decimal[3];
                  retValue.prices[0] =  1.0M;
                  retValue.prices[1] =  2.0M;
                  retValue.prices[2] =  3.0M;
                  return retValue;
            }
0
 

Author Comment

by:rmmarsh
ID: 17825399
I really need the structore to be an array of the structure:

    private struct isbnAndPrices
    {
        public string isbn;
        public decimal high, low, average;
    }
    isbnAndPrices[] retValue;

However, when I try to access the member "isbn", it is not visible... Why?  Can I still return an array of this struct?
0
 

Author Comment

by:rmmarsh
ID: 17825541
Ignore my last post... I found the problem...
0
 

Author Comment

by:rmmarsh
ID: 17825767
Thanks...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question