Solved

How to return a 'struct' from a web service

Posted on 2006-10-27
4
259 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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