Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to return a 'struct' from a web service

Posted on 2006-10-27
4
Medium Priority
?
289 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…

705 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