也许一个具体的例子也很有用。假设您可以调用 AndroidHttpClient 来执行 HttpPost,您可以利用一个简单的 asp.net mvc 控制器操作来处理帖子(作为 xml)并相应地返回 xml(或其他)供您解析。
对于您的 asp.net mvc 操作,请尝试以下操作(路由到http://foo.com/Something/ProcessSomething):
...
[ ValidateInput(false)
]
public class SomethingController : Controller
{
...
[ HttpPost
]
public ActionResult ProcessSomething(SomeParameters Parameters, String Options)
{
...
String sProcessed = Parameters.Descriptor.ParamA + Parameters.Descriptor.ParamB;
...
return this.Content
( String.Format
( "<result><processed>{0}</processed></result>"
, sProcessed
)
, "text/xml"
);
}
/// <summary>
/// Description of a view model instance.
/// </summary>
[ XmlRoot("something")
]
public class SomethingDescriptor
{
private String _ParamA = String.Empty;
private String _ParamB = String.Empty;
[ XmlElement("paramA")
]
public String ParamA
{
set
{
this._ParamA = value;
}
get
{
return this._ParamA;
}
}
[ XmlElement("paramB")
]
public String ParamB
{
set
{
this._ParamB = value;
}
get
{
return this._ParamB;
}
}
}
/// <summary>
/// View parameter deserializer.
/// </summary>
public class SomethingParameters
{
private SomethingDescriptor _Descriptor = new SomethingDescriptor();
public SomethingDescriptor Descriptor
{
get
{
return this._Descriptor;
}
}
public String Something
{
set
{
try
{
using (StringReader sR = new StringReader(value))
{
XmlSerializer xS = new XmlSerializer(typeof(SomethingDescriptor));
this._Descriptor = xS.Deserialize(sR) as SomethingDescriptor;
}
}
catch
{
}
}
get
{
return String.Empty;
}
}
}
}
您的 android 应用程序会将诸如“Something=<something><paramA>this is pA</paramA><paramB>this is paramB</paramB></something>”之类的变量发布到http://foo.com/Something /ProcessSomething并取回可用于向用户呈现某些内容的 xml。