Solved

C# - Need to pass variable to a class

Posted on 2012-03-22
6
318 Views
Last Modified: 2012-08-13
I have the below code in an ASP.NET page.  It works fine.  I need to modify it.  I wrote a WCF Service and I need to call that service in the class below.  I know how to do that.

The issue I'm having is I need to pass an ID to the class to be used by my WCF Service.  Any ideas?

    //FILES
    public class FileList
    {
        static FileList()
        {
            getFiles = new List<Files>();
            getFiles.Add(new Files() { FileName = "Test.1zip" });
            getFiles.Add(new Files() { FileName = "Test2.zip" });
            getFiles.Add(new Files() { FileName = "Test3.zip" });
       }
        public static List<Files> getFiles { get; set; }
    }

    public class Files
    {
        public string FileName { get; set; }
    }
0
Comment
Question by:CipherIS
  • 3
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37754540
create an operation contract with parameter named ID of your type.
Let's say the service looks like:-
[ServiceContract]
interface IMyService
{
[OperationContract]
string Operation(int ID);
}

public class MyService : IMyService
{
public string Operation(int ID)
{
return ID.ToString();
}
}

//Here is the client Code
using(var proxy=new MyServiceClient())
{
var strRet=proxy.Operation(10);
//Here 10 would be returned
}

Open in new window

0
 
LVL 1

Author Comment

by:CipherIS
ID: 37754556
My WCF is fine.  I just need to pass the ID to the class and use that ID in the class.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37754567
Expose a property or method which takes in a parameter for the information you would like to receive. It's difficult to tell from the code you posted as to the desired result.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37754602
i have passed ID in the my example and used it in Service Class
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37754733
I've attached my code in a text file.  I put a comment where I need the UserName to be passed.

Please let me know how to resolve this.

Thanks
Pass-UserName-to-AccountList.txt
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37754774
I figured it out.  Thaks for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 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

10 Experts available now in Live!

Get 1:1 Help Now