开发者

Getting List on WCF ChannelFactory Generated Client Proxy when IList is used in the Entity

There is a famous issue with WCF which is serializing IList as array (instead of list) to the client. There are also known solutions which can be applied when the client is using svcutil or the Visual Studio IDE for creating the service reference for the client. However, we are using ChannelFactory to generate a service proxy to the client at run time. In other words, we don't use svcutil nor the IDE to create a re开发者_如何学运维ference to the service. Is there an appropriate solution to this problem with this scenario?


Sounds like you're trying to do something similar to what I describe in my answer to a question on IList with NHibernate & WCF. Since you are sharing the contract assembly between the service and the client, the List deserialization code will also be shared. I have used this technique with a ChannelFactory approach successfully, hope it works for you.


In your service interface, is your return type list? Is just did a short test,

Server:

class Program
{
    static void Main(string[] args)
    {
        ServiceHost host = new ServiceHost(typeof(TestService), new Uri("http://localhost:1024/TestService"));
        host.Open();
        Console.ReadLine();
    }
}

public class TestService : ITestService
{
    public List<string> GetStrings(string test)
    {
        return new List<string>() {test};
    }
}

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    List<string> GetStrings(string test);
}

Client

 static void Main(string[] args)
    {
        ChannelFactory<ITestService> factory = new ChannelFactory<ITestService>(new BasicHttpBinding());
        ITestService proxy = factory.CreateChannel(new EndpointAddress(new Uri("http://localhost:1024/TestService")));
        var list = proxy.GetStrings("Test");
    }

And list will be of type List. Did you handle anything different in your implementation?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜