Array instead of List in WCF Service Proxy Generated using svcutil.exe

馋奶兔 提交于 2019-12-11 10:35:01

问题


I have a ServiceContract,

using System.Collections.Generic;
using System.ServiceModel;
namespace MainModule.Sub.Communication
{
    [ServiceContract]
    public interface IWebMethod
    {
        [OperationContract(IsOneWay = false)]
        bool InvokeAlert(List<int> userIds);

        [OperationContract(IsOneWay = false, Name = "InvokeAlertByMainID")]
        bool InvokeAlert(List<int> userIds, int mainId);

        [OperationContract(IsOneWay = true)]
        void DeletePopupNotifications(System.Data.DataSet deletedNotifications);
    }
}

I used below command to generate proxy (I have to do this using command-line not via Add Service Reference.

SvcUtil.exe http://localhost/MainCommunicationServer/wm  /ct:System.Collections.Generic.List`1 /out:HTTPRouterServerProxy.cs 

Even I added the ct switch (collectionType) the proxy is Generating it as Array (int[]). How can I do that without using Add Service Reference window in VS


回答1:


If I remember correctly, the /ct switch may not have any effect (in some circumstances?) on OperationContract-level collections. Try using a wrapper DataContract type, e.g. bool InvokeAlert(InvokeAlertRequest r); where InvokeAlertRequest will be a [DataContract] type containing one [DataMember] List<int> userIds;




回答2:


The /ct switch stops working if SvcUtil fails to create a proxy that uses the DataContractSerializer and uses the XmlSerializer instead.

This is just a guess but I suspect that System.Data.DataSet might be causing this.



来源:https://stackoverflow.com/questions/14101245/array-instead-of-list-in-wcf-service-proxy-generated-using-svcutil-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!