0

我一直在使用 webServices 进行序列化对象实现,数据将由我在 webservices 中执行以下操作的桌面应用程序使用,它工作正常:

        [WebMethod]
        public byte[] getPartners()
        {
            string[] strFiles = Directory.GetFiles(GlobalStatic.rootAppData + @"\partners");

            List<DentalSock.main.partner> _partners = new List<DentalSock.main.partner>();
            foreach (String str in strFiles)
            {
                DentalSock.main.partner ptn = new DentalSock.main.partner();
                ptn.readPartner(str.Replace(GlobalStatic.rootAppData + @"\partners\", "").Replace(".xml", ""));
                _partners.Add(ptn);
            }

            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, _partners);
            return ms.ToArray();                  
        }

然后,当我回到客户端消费者时,我调用 web 服务将对象反序列化为具有以下代码的通用列表:

        ServiceReference1.partnerSoapClient p = new ServiceReference1.partnerSoapClient();
        byte[] byteArray = p.getPartners();
        MemoryStream stream = new MemoryStream(byteArray, 0, byteArray.Length);
        stream.Write(byteArray, 0, byteArray.Length);

        BinaryFormatter bf = new BinaryFormatter();

        pList = (List<partner>)bf.Deserialize(stream);

一切似乎都很好,但是在最后一行调用 Deserialize 方法时没有任何反应,没有异常,当我尝试调试器时,当黄色突出显示的行到达上面代码的最后一行时,进入调试器模式只是停止并显示窗体!请帮助解决这个问题,因为我不明白!

4

1 回答 1

0

The code is now working pretty cool what I did was to put all the code under the DoWork event of a backgroundworker then I call the RunWorkerAsync() method on the Load event of the form and everything started to work the way around it was maybe related to the main thread.

于 2013-04-29T17:35:52.767 回答