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
Solved

How to return a 'struct' from a web service

Posted on 2006-10-27
4
266 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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