问题
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