将数据从Windows Mobile传输到服务器并检索 [英] transfer data from windows mobile to server and retrieve it

查看:100
本文介绍了将数据从Windows Mobile传输到服务器并检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友!

我想从Windows Mobile向服务器发送数据,例如imei no.我们在服务器上有asp.net应用程序.请告诉我如何发送它并检索发送的数据,以便我们可以将其插入数据库.
谢谢



这是我所做的.客户端程序

hello friends!!

I want to send data e.g imei no to server from windows mobile. we have asp.net application on the server . Please tell me how to send this and retrieve the sent data, so that we can insert it into database.
Thank you



this what i have done. Client side program

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Client
{
    public partial class Form1 : Form
    {
        string url = "http://localhost/testwebsite/default.aspx?field1=name";
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_Send_Click(object sender, EventArgs e)
        {
            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
               
            }
            catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); }
        }
    }
}


服务器端程序:


Server side program:

protected void Button1_Click(object sender, EventArgs e)
   {
       try
       {
           String s = Request.QueryString["field1"];
           Label1.Text = "value got:" + s.ToString();
       }
       catch (Exception ex) { Label1.Text = ex.Message.ToString(); }


   }


我这样做只是为了测试.
但是在asp.net网站上单击按钮时出现以下错误
对象引用未设置为对象的实例.


This i have done just for testing purpose.
but am getting the following error when click on the button in asp.net website
Object reference not set to an instance of an object.

推荐答案

使用ASP.Net Web服务并从Windows Mobile应用程序中调用该服务您可以在其中获取该信息,并可以在Web服务中编写代码以将数据保存到db.

以下链接可能会帮助您在Windows Mobile应用程序中获取设备信息

http://www.codeguru.com/forum/showthread.php?t=444933 [ ^ ]
http://social.msdn.microsoft.com /Forums/zh-CN/vssmartdevicesvbcs/thread/c10f1962-257f-449a-84be-bc4e25753099/ [您的第一个C#Web服务 [ ASP.NET Web服务 [
Use ASP.Net web service and call that service from your windows mobile application where you can get that information and in the web service you can write the code to save the data to db.

Following links might help you to get Device information in windows mobile application

http://www.codeguru.com/forum/showthread.php?t=444933[^]
http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/c10f1962-257f-449a-84be-bc4e25753099/[^]

Links for creating web service

Your first C# Web Service[^]
ASP.NET Web Service[^]

For a while if you don''t want to go through creating web service then do one thing create a web service project in vs the helloword method will created for you

copy that and rename put a string parameter imieno and in function body save that value to db.
--Pankaj


没有将数据传输到"服务器"之类的东西.通常,服务器是一台机器.它的功能完全取决于它所运行的软件,并且没有通用的名称.您需要确定服务器部分软件应该做什么(如果不需要常规的FTP或HTTP服务器,则可以开发此类软件),而不仅仅是您应该考虑特定客户端部分应该做什么.


回答后续问题:
现在我知道服务器是HTTP.我不明白为什么常规Web客户端不是一个选择.可能是一些本地代码(应该包含移动客户端系统).在这种情况下,您需要使用类System.Net.HttpWebRequest:向服务器发送请求(我想使用POST方法).检查您使用的所有API是否可用于您的系统.我在Framework v.2.0、3.0和3.5(
http://msdn.microsoft.com/zh-CN /library/system.net.webrequest.aspx [ ^ ].该类是抽象类,但运行时类将是System.Net.HttpWebRequest,因为它将通过工厂WebRequest.Create方法构造,该方法将通过您的URL选择合适的运行时.
上面的示例只是一个骨架.
我为您找到了一个更详细的示例,这次是使用"POST"方法并实际发送一些数据的示例.它应该非常接近您的客户端代码.此处: http://msdn.microsoft.com/en-us/library/debx8sh9.aspx [< ^ ].

您可以使用一些可用的正在运行的网站对其进行测试.

—SA
There is no such thing as "transfer data" to "just server". Usually, the Server is a machine. What it does totally depends on the software it runs, and there is nothing generic about it. You need to decide what your server-part software should do (and perhaps develop such software if a regular FTP or HTTP server is not what you need), only than you should think what a particular client part should do.


Answering follow-up Question:
Now I understand the server is HTTP. I did not get why a regular Web client is not an options. Probably some local code (and the Mobile client system should be involved). In this case, you need to use the class System.Net.HttpWebRequest: send a request (using POST method, I presume) to the server. Check is all the API you use is available for your system. I found platform compatibility information on the help pages for Framework v.2.0, 3.0 and 3.5 (http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.90).aspx[^]), but by some reason not for 4.0. (maybe this version is not yet ready for this platform?). Anyway, I think it should be available on the Framework already installed on your mobile device.

Look at the code sample here: http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[^]. This class is abstract, but run-time class will be System.Net.HttpWebRequest, as it will be constructed via the factory WebRequest.Create method which will select appropriate run-time by your URL.

The example above is just a skeleton.
I have found a more detailed sample for you, this time the one using "POST" method and actually sending some data. It should be very close to your client code. Here: http://msdn.microsoft.com/en-us/library/debx8sh9.aspx[^].

You can test it using some available running Web site.

—SA


这篇关于将数据从Windows Mobile传输到服务器并检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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