Migrate ASMX web method to WCF which accepts string array

46 Views Asked by At

I have one legacy ASMX service which is consumed by many clients (java, .Net, Python etc). I want to upgrade ASMX service to WCF without impacting my clients (means they will not do any change in their code)

Below function works fine in ASMX:

[WebService(Namespace = "http://example.com/Report", Description = "Save")]
    public class Report : WebService
    {
      
        [WebMethod(Description = "Save")]

        public void Save(string name, string[] skills)
        {
        }
    }

It means when client calls Save method and pass name (string) and skills (string[]) parameter then I get it at service end which I further save in database.

In WCF I wrote below interface and class:

[ServiceContract(Namespace = "http://example.com/Report")]
public interface IReport
{
    [OperationContract(Action = "http://example.com/Report/Save")]
    void Save(string name, string[] skills);
}

public class Report : IReport
{
    public void Save(string name, string[] skills)
    {
       
    }
}

When I call WCF service from same legacy client then I get name value but not skills value (which is string[]).

Please help how I can get the string[] values. I cannot change client code.

I expect that when I change ASMX to WCF then it should work without impacting my clients. I am unable to get value of skills (which is string array).

It seems in WCF, system is unable to desterilize the string array. I tried with List instead of string[] but also did not work.

1

There are 1 best solutions below

3
QI You On

Try this code:

[ServiceContract(Namespace = "http://example.com/Report")]
public interface IReport
{
    [OperationContract(Action = "http://example.com/Report/Save")]
    void Save(string name, Skills skills);
}
[DataContract]
public class Skills
{
    [DataMember]
    public string[] Skillsarray { get; set; }
}

public class Report : IReport
{
    public void Save(string name, Skills skills)
    {
       
    }
}