在.Net Web服务中接收XML [英] Receiving XML in a .Net Web Service

查看:85
本文介绍了在.Net Web服务中接收XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web服务问题...

我正在构建一个Web服务,以将xml数据来回传递给android平板电脑.我将控制此服务的两端,因此第三方将无法使用它.该Web服务是用C#编写的.我的问题是...参数之一将是Android平板电脑用户的userId,但我还需要传递将要写入服务器上的master数据库的结构数据,并使用数据.我正在考虑只接受一个xml字符串作为第二个参数,该参数包含我需要的结构中的数据.请告知这是否是一个不错的选择,如果可以,我可以在确定如何在Web服务的C#Web方法中编写代码方面提供一些帮助.任何帮助将不胜感激...

Web Service Troubles...

I''m building a web service to pass xml data back and forth to android tablets. I will control both ends of this service, so it will not be available to third parties. The web service is being written in C#. My question is this... One of the parameters will need to be the userId of the Android tablet user, but I also need to pass structure data that I will be writing to a master database on a server and do some other processes with the data. I was thinking of just accepting an xml string as the second parameter that contains the data in the struct that I need. Please advise if this is a good option and if it is, I could use a little help on figuring out how to code this up in the C# web method in the web service. Any help would be appreciated...

推荐答案

您可以使用内部类创建所需的数据结构,如下所示:
You can create the required data structure with inner class as:
public class androidData
{
    public String userID{get;set;}
    public class InnerStruct
    {
       public int InnerID{get;set;}
    }
}



之后,可以使用以下操作编写服务器代码以更新数据:



Later, server code can be written to update the data using the below operation:

[WebMethod]
public bool UpdateOperation(DataSet androidClient)

{
   if (!this.Open())  
      return true;

   SqlDataAdapter oDSCommand = new SqlDataAdapter("sqlqurey..",this.oConn);
   SqlCommandBuilder oCmdBuilder = new SqlCommandBuilder(oDSCommand); 

   int lnRows = 0;
   try
   {
      lnRows = oDSCommand.Update(androidClient,"DBTable");
   }
   catch(Exception e)
   {
      return false;
   }
 

   if ( lnRows < 1 )
      return false;
   return true;
}


感谢您的回答.让我重申您在说什么,以便确保我正确理解.我应该将DataSet而不是xml结构作为字符串传递给Web方法函数.很有意思,我不知道从基于Java的应用程序中调用函数时可以做到这一点.您能告诉我如何从android上的java代码调用web方法吗?再次感谢您的答复.
Thank you for your answer. Let me reiterate what you''re saying so I''m sure that I''m understanding it correctly. I should pass a DataSet to the web method function instead of an xml struct as a string. That is interesting, I didn''t know I could do that when calling the function from a java based application. Can you show me how I would call the web method from the java code on the android? Again, I appreciate your response.


这篇关于在.Net Web服务中接收XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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