0

I have a list defined as below in each of 11 different classes (which handle web-services)

private List<edbService> genEdbService;

internal class edbService
{
    public string ServiceID { get; set; }
    public string ServiceName { get; set; }
    public string ServiceDescr { get; set; }
    public string ServiceInterval { get; set; }
    public string ServiceStatus { get; set; }
    public string ServiceUrl { get; set; }
    public string SourceApplication { get; set; }
    public string DestinationApplication { get; set; }
    public string Function { get; set; }
    public string Version { get; set; }
    public string userid { get; set; }
    public string credentials { get; set; }
    public string orgid { get; set; }
    public string orgunit { get; set; }
    public string customerid { get; set; }
    public string channel { get; set; }
    public string ip { get; set; }
}

The list is populated in each class by reading the web-service configuration data from xml files in each class:

public DCSSCustomerCreate_V3_0()
{
try
{
    XElement x = XElement.Load(global::EvryCardManagement.Properties.Settings.Default.DataPath + "CustomerCreate.xml");
    // Get global settings        
    IEnumerable<XElement> services = from el in x.Descendants("Service")
         select el;
    if (services != null)
    {
        edb_service = new List<edbService>();

        // edb_service= Common.populateEDBService("CustomerCreate.xml");

        foreach (XElement srv in services)
        {
        edbService edbSrv = new edbService();

        edbSrv.ServiceID = srv.Element("ServiceID").Value;
        edbSrv.ServiceName = srv.Element("ServiceName").Value;
        edbSrv.ServiceDescr = srv.Element("ServiceDescr").Value;
        edbSrv.ServiceInterval = srv.Element("ServiceInterval").Value;
        edbSrv.ServiceStatus = srv.Element("ServiceStatus").Value;
        edbSrv.ServiceUrl = srv.Element("ServiceUrl").Value;
        foreach (XElement ServiceHeader in srv.Elements("ServiceHeader"))
        {
        ... 

now what I want to do is have this code in one place in my Common.cs class so I tried:

public static List<edbService> populateEDBService(string xmlDataFile)
{
    try
    {
    XElement x = XElement.Load(global::EvryCardManagement.Properties.Settings.Default.DataPath + xmlDataFile);

    // Get global settings
    IEnumerable<XElement> services = from el in x.Descendants("Service")
         select el;
    if (services != null)
    {
      //edb_Service = new List<edbService>();
      foreach (XElement srv in services)
      {
      edbService edbSrv = new edbService();

      edbSrv.ServiceID = srv.Element("ServiceID").Value;
      edbSrv.ServiceName = srv.Element("ServiceName").Value;
      edbSrv.ServiceDescr = srv.Element("ServiceDescr").Value;
      edbSrv.ServiceInterval = srv.Element("ServiceInterval").Value;
      edbSrv.ServiceStatus = srv.Element("ServiceStatus").Value;
      edbSrv.ServiceUrl = srv.Element("ServiceUrl").Value;

      foreach (XElement ServiceHeader in srv.Elements("ServiceHeader"))
        {
        edbSrv.SourceApplication = ServiceHeader.Element("SourceApplication").Value;
        edbSrv.DestinationApplication = ServiceHeader.Element("DestinationApplication").Value;
        edbSrv.Function = ServiceHeader.Element("Function").Value;
        edbSrv.Version = ServiceHeader.Element("Version").Value;

        foreach (XElement ClientContext in ServiceHeader.Elements("ClientContext"))
          {
          edbSrv.userid = ClientContext.Element("userid").Value;
          edbSrv.credentials = ClientContext.Element("credentials").Value;
          edbSrv.orgid = ClientContext.Element("orgid").Value;
          edbSrv.orgunit = ClientContext.Element("orgunit").Value;
          edbSrv.customerid = ClientContext.Element("customerid").Value;
          edbSrv.channel = ClientContext.Element("channel").Value;
          edbSrv.ip = ClientContext.Element("ip").Value;
          }
        }

     // populateEDBService.Add(edbSrv);
     }
}
}
catch (Exception ex)
{
    /* Write to log */
    Common.logBuilder("CustomerCreate : Form --> CustomerCreate <--", "Exception", Common.ActiveMQ,
       ex.Message, "Exception");
    /* Send email to support */
    emailer.exceptionEmail(ex);
    }
return;
}

Now I get a compile error on the return; saying that An object of a type convertible to 'System.Collections.Generic.List<EvryCardManagement.Common.edbService>' is required

and in the class that should call this method, I want to do something like:

edb_service = Common.populateEDBService("CustomerUpdate.xml");

but I get an error Cannot implicitly convert type 'System.Collections.Generic.List<EvryCardManagement.Common.edbService>' to 'System.Collections.Generic.List<EvryCardManagement.CustomerUpdate.edbService>'

So firstly how should I return the list from my generic method and how should I call it to return the list populated with the configuration data?

1 Answer 1

3

It sounds like you have your class edbService defined in two namespaces,

EvryCardManagement.Common and EvryCardManagement.CustomerUpdate

I would suggest defining it in only EvryCardManagement.Common and have everything reference it from there.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks (that works!), but how should I write it so that the method returns a populated list?
You just need to add a declaration of a local variable of type List<edbService>. Then add edbService objects to this list in your loop, then return the list at the end of the function.
I tried edb_service = Common.populateSoapBody<edbService>("CardUpdate.xml"); to call the procedure but I get an error
What is populateSoapBody? What is the error? Worthe closing this thread and starting a new one?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.