Solved

C# - Need to pass variable to a class

Posted on 2012-03-22
6
317 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 74

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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: …

757 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