【问题标题】:Web service cast exception why?Web 服务强制转换异常为什么?
【发布时间】:2010-10-10 23:20:15
【问题描述】:
Error Cannot implicitly convert type 'string[]' to 'System.Collections.Generic.List<string>'

上述错误是我调用Web服务的方法时引起的

List<string> bob = myService.GetAllList();

其中:GetAllList =

[WebMethod]
        public List<string> GetAllList()
        {

            List<string> list ....
            return list;
        }

我已经重建了整个解决方案,更新了服务引用,但我仍然得到一个转换异常有什么想法吗?

【问题讨论】:

    标签: c# .net web-services exception serialization


    【解决方案1】:

    SOAP 协议不支持泛型集合。

    试试这个:

    List<string> bob = new List<string>(myService.GetAllList());
    

    【讨论】:

      【解决方案2】:

      你需要这样做:

      List<string> bob = new List<string>(myService.GetAllList());
      

      泛型列表的构造函数的重载采用指定类型的 IEnumerable 来初始化数组。你不能像异常状态一样,隐式地将其直接转换为该类型。

      安德鲁

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-05
        • 2023-03-19
        • 2010-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-22
        • 1970-01-01
        相关资源
        最近更新 更多