WCF问题 [英] WCF issues

查看:46
本文介绍了WCF问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我有一个WCF服务库,名称为ServerWCF,其中包含一个"AdminService".服务.该服务的方法之一是List< Station>站点. LoadStation(),应该从我的数据库中返回火车站列表.

Hello guys! I have a WCF service library, name ServerWCF, which contains a "AdminService" service. One of the methods of this service is List<Station> LoadStation() which should return a List of train stations from my database.

我也有一个WPF客户端,并且正在使用一个下拉菜单,其中应包含车站的城市.当我在名为AdminServiceReference的客户端中添加服务引用时,我注意到该方法的签名是Station [] Load Station()而不是 在List< Station> LoadStation()上.我不知道我对此无能为力,因为代码是在客户端自动生成的,但是无论如何(我使用了reshaper重构建议,但没有任何区别).问题是在下面 代码,永远不会访问foreach行.我在上面的行上放置了一个断点,我进入并注意到服务器返回的列表包含了所有工作站,这是一件好事,但是当我退出并跨过之后,程序将无法运行 到填充下拉列表的foreach,但返回到第二行,这就是为什么我的下拉列表显然仍然为空,寂寞和悲伤的原因:(关于如何解决此问题的任何提示?PS:相同的代码可以正常工作当我的列表是ArrayList时 仅包含城市,但我需要所有对象.

I also have a WPF Client, and I'm using a dropdown that should contain the Cities of the stations. When I added the Service Reference in the client, named AdminServiceReference, i noticed that the signature of the method is Station[] Load Station() instead on List<Station>LoadStation(). I don't know if I can do anything about this as the code is generated automatically in the client, but whatever(I used the resharper refactoring suggestion, but didn't make any difference). The problem is that on the below code, the foreach line is never accessed. I placed a breakpoint on the line above, I stepped into and noticed that the list returned by the Server contains all of the station, which is a good thing, but after i step out and step over, the program is not going to the foreach that populates the dropdown, but returns to the second line, which is the reason why, obviously, my dropdown remains empty, lonely and sad :( Any tip on how can i sort this out? PS: that same code worked fine when my list was a ArrayList and was containing only Cities, but I need all the objects.

客户代码:

private void fromStationCB_DropDownOpened(object sender, EventArgs e)
        {
            var adminProxy = new AdminServiceClient();
            fromStationCB.Items.Clear();
            var list = adminProxy.LoadStations();
            foreach (var items in list)
                fromStationCB.Items.Add(items.City);
            label5.Content = "";
        }

Server code:

public List<Station> LoadStations()
        {
            List<Station> list = new List<Station>();
            using (var context = new RailwaySystemModelContainer())
            {
                /*foreach (var station in context.Stations)
                    list.Add(station);*/
                list.AddRange(context.Stations);
                return list;
            }
        }

推荐答案

fromStationCB_DropDownOpened(对象发送者,EventArgs e)

fromStationCB_DropDownOpened(object sender, EventArgs e)

{

var adminProxy = new AdminServiceClient();

var adminProxy = new AdminServiceClient();

fromStationCB.Items.Clear();

fromStationCB.Items.Clear();

变量列表= adminProxy.LoadStations();

foreach(列表中的可变项)

foreach (var items in list)

          fromStationCB.Items.Add(items.City);

         fromStationCB.Items.Add(items.City);

label5.Content ="; }

label5.Content = ""; }


您确定变数列表"吗? (粗体部分)是否包含值不为空?如果列表"中没有值,则返回"0".您的循环将不会执行.


Are you sure "var list" (bold part) is contains value not empty? If there is no value in "list" your loop will not execute.


这篇关于WCF问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆