【发布时间】:2011-11-04 05:59:42
【问题描述】:
我正在尝试从 silverlight 应用程序中的 Web 服务获取数据。不幸的是,silverlight 应用程序(必应地图应用程序)在尝试连接时只是挂起。
我在控制台应用程序中使用相同的代码,它工作得很好。
我需要在 silverlight 中做些什么才能让它工作吗?我没有遇到任何异常 - 它只是挂起。
我的服务和客户端代码基于此示例 http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication
问题和疑问:
1.为什么我不能在我的 sliverlight 代码中设置断点?
2。如何从 silverlight 应用程序成功调用 WCF 服务?(指向 SIMPLE 工作示例的链接会很棒 - 我似乎找到的所有示例似乎都非常先进(RIA、Duplex 等)其中许多还显示xml 和其他非 C#“代码”——坦率地说,我不知道它们是做什么的以及它们与项目、代码和服务的关系。
(显然我对WCF和silverlight一无所知)
根据对代码的要求:
[ServiceContract]
public interface ILGSMapServer
{
[OperationContract]
List<double> GetLatitudes();
}
public class TreeWorkClient
{
ChannelFactory<ILGSMapServer> httpServer;
public ILGSMapServer httpProxy;
public TreeWorkClient()
{
httpServer = new ChannelFactory<ILGSMapServer>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8000/GetLatitudes"));
httpProxy = httpServer.CreateChannel();
}
public List<TreeWorkItem> GetLocations()
{
List<double> lats = httpProxy.GetLatitudes();
//... do stuff in code
return ret;
}
}
【问题讨论】:
-
请实际显示您用来调用服务的代码。
-
很确定你需要 AsyncPattern = true 在你的 OperationContract for silverlight
-
@MerickOWA - 我不知道那是什么。那在哪里/那是什么?如何设置?
-
@Tim 我发布了一个答案,其中显示了您需要更改的示例
标签: c# silverlight wcf