[英]Sending a data from android phone to pc?
I am creating a "tracking system" for my android phone. 我正在为我的Android手机创建一个“跟踪系统”。 Basically, the phone would transmit it latitude/longitude to a C# program that will receive the coordinates and display it on a map. 基本上,电话会将纬度/经度传输到C#程序,该程序将接收坐标并将其显示在地图上。 I managed to get the phone's latitude/longitude coordinates but I need a way to transmit that data to my C# application running in my PC. 我设法获得了手机的纬度/经度坐标,但是我需要一种方法来将该数据传输到在PC上运行的C#应用程序中。 I know my way around C# and Java but never really got into network programming. 我知道我使用C#和Java的方式,但从未真正涉足网络编程。 Is there a way to do this ? 有没有办法做到这一点 ?
I'd look into C# Webservices, very powerful. 我将研究功能非常强大的C#Web服务。 The communication protocol is SOAP (Simple Object Access Protocol) which is a popular and well supported standard. 通信协议是SOAP(简单对象访问协议),它是一种流行且受到良好支持的标准。
Good starting reference: Your first C# Web Service 良好的入门参考: 您的第一个C#Web服务
I can't speak to the C# side of it, but if you write a C# server to receive post requests, the Apache HttpClient makes it relatively simple to send requests. 我不能说它的C#端,但是如果您编写一个C#服务器来接收发布请求,则Apache HttpClient使得发送请求相对简单。 There are a bunch of other questions on SO that will help with setting up the client side on your phone if you poke around a bit. SO上还有许多其他问题,如果您稍加拨动,将有助于在手机上设置客户端。
You have different way to do it. 您有不同的方式来做。
The correct way to do it would be to build WCF service which allows many different protocols to receive data. 正确的方法是构建WCF服务,该服务允许许多不同的协议接收数据。 This would could be a very powerful solution that can be extended in future. 这将是一个非常强大的解决方案,可以在将来扩展。
The fastest and easiest IMO would be to create ASP.NET MVC application, define a POCO Model for your longitude/latitude and create an action that would take your Model as parameter. 最快和最简单的IMO将是创建ASP.NET MVC应用程序,为您的经度/纬度定义POCO模型,并创建一个将模型作为参数的操作。 Then use HttpClient and HttpPost on android to send the data. 然后在android上使用HttpClient和HttpPost发送数据。 The trick here is to name the variables in your post request same as ones you define in your C# Model. 这里的窍门是为发布请求中的变量命名,使其与您在C#模型中定义的变量相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.