Solved

How to return a 'struct' from a web service

Posted on 2006-10-27
4
234 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
  • 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now