什么是最便携的方式让一个Silverlight和放大器;普通.NET REST客户端 [英] What's the most portable way to make a Silverlight & Regular .NET REST client

查看:118
本文介绍了什么是最便携的方式让一个Silverlight和放大器;普通.NET REST客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个服务器应用程序,以公开使用WCF的一些状态信息。 特别是我使用WCF服务与REST风格的API之后我。 墙上的我打几分,当涉及到从一个Silverlight消费的REST API 应用程序/页,我想有作为额外类型的客户端...

I'm trying to get a Server application to expose some status information using WCF. In particular I'm after using WCF services with RESTful "API". I'm hitting somewhat of a wall when it comes to consuming the REST api from a silverlight app/page that I want to have as an additional type of client...

到目前为止,我已经成功地定义一个状态界面:

So far I've been successful in defining a status interface:

public static class StatusUriTemplates
{
  public const string Status = "/current-status";
  public const string StatusJson = "/current-status/json";
  public const string StatusXml = "/current-status/xml";
}
[ServiceContract]
public interface IStatusService
{
  [OperationContract]
  [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = StatusUriTemplates.StatusJson)]
  StatusResultSet GetProgressAsJson();

  [OperationContract]
  [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = StatusUriTemplates.StatusXml)]
  StatusResultSet GetProgressAsXml();

  [OperationContract]
  [WebGet(UriTemplate = StatusUriTemplates.Status)]
  StatusResultSet GetProgress();
}

实现它在服务器:

Implementing it in the server:

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
  public class ServerStatusService : IStatusService
  {
    public StatusResultSet GetProgressAsJson()
    { return GetProgress(); }

    public StatusResultSet GetProgressAsXml()
    { return GetProgress(); }

    public StatusResultSet GetProgress()
    {
       return StatusResultSet.Empty;
    }
  }

这是我的code在运行时将其暴露:

Exposing it from my code at runtime:

  var service = new ServerStatusService();
  var binding = new WebHttpBinding();
  var behavior = new WebHttpBehavior();

  var host = new WebServiceHost(service, new Uri("http://localhost:8000/server"));
  host.AddServiceEndpoint(typeof(IStatusService), binding, "status");
  host.Open();

我甚至已经成功使用的东西沿着这行消费从.NET控制台/ winfoems / WPF应用程序的服务:

I've even been successful with consuming the service from a .NET console/winfoems/WPF application using something along the line of this:

  var cf = new WebChannelFactory<IStatusService>(new Uri("http://localhost:8000/server/status"));
  var ss = cf.CreateChannel();
  Console.WriteLine(ss.GetProgress().TimeStamp);

华尔街我打的是没有WebChannelFactory的Sliverlight的。

The "wall" I'm hitting is that there is NO WebChannelFactory for SliverLight.

期。

这意味着,当谈到Silverlight的code,我的选择是:

This means that when it comes to silverlight code, my options are:

  • 在使用Web客户端写丑code, 这最终意味着我将有 更新两套code时 我有一个改变我的API
  • 使用SOAP / WS为WebService,并保持 从更新服务引用 Visual Studio中
  • Write ugly code using WebClient, which ultimately means I will have to update two sets of code whenever I have a change to my API
  • Use SOAP/WS for the WebService and keep updating the service reference from Visual Studio

有没有一种方法,以保持干净的实施与WebChannelFactory在Silverlight? 也许一个公共领域/开源WebChannelFactory Silverlight的?

Is there a way to keep the "clean" implementation with WebChannelFactory in SilverLight? Perhaps a public domain / open source WebChannelFactory for SilverLight?

任何帮助,这将大大AP preciated!

Any help with this will be greatly appreciated!

推荐答案

您缺少Spring.Rest: http://springframework.net/index.html#spring-rest-1.0 .0发布

You are missing Spring.Rest : http://springframework.net/index.html#spring-rest-1.0.0-released

这篇关于什么是最便携的方式让一个Silverlight和放大器;普通.NET REST客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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