简体   繁体   English

如何在Xamarin和Windows Phone中创建RESTful Web服务?

[英]How to create a RESTful webservice in Xamarin and Windows Phone?

I am currently trying to find a solution on how to create (not consume!!!) a RESTful service with Xamarin for Android and on Windows Phone. 我目前正在尝试寻找一种解决方案,该解决方案涉及如何使用Xamarin for Android和Windows Phone创建(不消耗!)RESTful服务。 I already searched for it, but only found libraries and solutions on how to consume a RESTful webservice on those platforms. 我已经在搜索它,但是只找到了有关如何在这些平台上使用RESTful Web服务的库和解决方案。 Do you know any good library to create a webservice on those platforms or any hints on how to implement a simple werbservice (not using ASP.NET)? 您是否知道在这些平台上创建Web服务的任何好的库,或者有关如何实现简单的werbservice(不使用ASP.NET)的任何提示?

TIA Octo TIA Octo

The Xamarin.NET and WinRT frameworks (and their package ecosystems) have pretty comprehensive support for web services etc. from a client perspective, but not so much if you want to act as the host. 从客户端的角度来看,Xamarin.NET和WinRT框架(及其包生态系统)对Web服务等具有相当全面的支持,但是如果您要充当主机,则没有那么多的支持。 You can't install something like webapi or signalr host into a PCL, or even the native platform projects. 您不能在WebL或本机平台项目中安装Webapi或Signalr主机之类的东西。

Based on your clarification comments, I would suggest one of the two approaches below. 根据您的澄清意见,我将建议以下两种方法之一。 I will assume that the RESTful requirement is more of a "nice to have", and the "calling methods with parameters and getting results" is the priority. 我将假设RESTful要求更像是“很不错”,而“具有参数并获得结果的调用方法”是优先事项。

1. Make the mobile apps clients too - remove the hosting requirement from the mobile devices by adding a hub on another server with the full .NET profile. 1.也使移动应用程序成为客户端 -通过在具有完整.NET配置文件的另一台服务器上添加集线器,从移动设备中删除对托管的要求。 Both your mobile apps and your "test runner" connect to this and the hub routes the messages between them. 您的移动应用程序和“测试运行程序”都与此连接,并且集线器在它们之间路由消息。 SignalR would handle this easily. SignalR将轻松处理此问题。 This option is not at all RESTful and requires an additional server, but is quick to get up and running and will easily support your desire to pass json messages back and forth. 此选项完全不是RESTful,需要额外的服务器,但是可以快速启动和运行,并且可以轻松支持您来回传递JSON消息的愿望。

2. Go lower level - Use sockets to facilitate communication directly between the mobile devices and "test runner". 2.移到更低的位置 -使用套接字促进移动设备与“测试运行程序”之间的直接通信。 The mobile devices can open sockets for listening, and your "test runner" connects to them direct. 移动设备可以打开插座进行监听,您的“测试跑步者”可以直接连接到它们。 Again, not RESTful and a bit more involved - you need to define a (hopefully) simple protocol (eg {length of type name}{type name}{length of payload}{payload}) and use that to send send and receive json - but it avoids needing a middle machine for routing. 再说一次,不是RESTful的,而是涉及更多的-您需要定义一个(希望)简单的协议(例如{type of name} {type name} {payload} {payload}),并使用该协议发送发送和接收json -但它避免了需要一台中间机器进行路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM