?
Solved

C# - Need to pass variable to a class

Posted on 2012-03-22
6
Medium Priority
?
322 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
[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
  • 2
6 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 2000 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
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 
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

Independent Software Vendors: 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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

764 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