开发者

Can't pass a List<Guid> as a parameter to a web-service in SL3

I have the following web-method:

namespace MessageService{
...
    [WebMethod]
    public ServiceReturnCodes SetMs开发者_StackOverflow社区g(List<Guid> Ids, DateTime processDateTime)
    {
        BL.SetMsg(Ids, DateTime.Now);   
    }
}

But when I call this method:

public List<Guid> Ids = new List<Guid>();
...
service.SetMsg(Ids, DateTime.Now);

I get the following error: Argument '1': cannot convert from 'System.Collections.Generic.List' to 'MessageWeb.MessageService.ArrayOfGuid' I can't figure out what ArrayOfGuid is and why it tries to convert.


I was just able to use ArrayOfGuid type to create a list and pass it as a parameter:

ArrayOfGuid Ids = null;
Ids.Add(Id);
....
service.SetMsg(Ids, DateTime.Now);


Maybe you have to convert it to an array using

service.SetMsg(Ids.ToArray() , DateTime.Now);


hi: yo can AddRange method to add elements to and of list :

[WebMethod]
public ServiceReturnCodes SetMsg(List<Guid> Ids, DateTime processDateTime)
{
    ArrayOfGuid _Ids = new List<Guid>();
    _Ids.AddRange(Ids);
    BL.SetMsg(_Ids, DateTime.Now);   
}


I believe that you'll find that the ArrayOfGuid is List<Guid>. Look in the Reference.cs. Here's what's in mine:

public class ArrayOfGuid : System.Collections.Generic.List<System.Guid> {}

So far, I've been able to use the partial class feature to make it a little easier to just pass a List<Guid>:

using System; using System.Collections.Generic;

namespace ConsoleApplication1.MessageServiceProxy
{
    partial class ArrayOfGuid
    {
        public ArrayOfGuid()
        {
        }

        public ArrayOfGuid(IEnumerable<Guid> guids) : base(guids)
        {
        }
    }
}

This allows you to pass new ArrayOfGuid(yourListOfGuid).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜