我使用android Ksoap2库来构建我的应用程序。
我想使用此库将复杂类型请求发送到我的C#WebService。
如何接收此请求?定义类?
非常感谢!
android代码:
private Runnable SendComplexRequest = new Runnable() {
@Override
public void run() {
String MemberLogin_SOAP_ACTIONComplex = "http://tempuri.org/EchoStringMessage";
SoapObject request = new SoapObject(NAMESPACE, "EchoStringMessage");
SoapObject test1 = new SoapObject(NAMESPACE, "test1");
test1.addProperty("Name","Peter");
test1.addProperty("age","100");
request.addSoapObject(test1);
Log.v("ObjString",request.toString());
try
{
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE("http://XXX.XXX.XXX.XXX/MytestWeb/WebService1.asmx");
androidHttpTransport.call(MemberLogin_SOAP_ACTIONComplex, envelope);
Object object = envelope.getResponse();
response = object.toString();
Log.v("Receive Message",object.toString());
}
catch(Exception e)
{
Log.v("Error", e.getMessage());
}
}
};
我得到了错误和日志:
V/ObjString﹕ EchoStringMessage{test1{Name=Peter; age=100; }}
V/Error﹕ System.Web.Services.Protocols.SoapException:伺服器無法處理要求。
---> System.NullReferenceException:並未將物件參考設定為物件的執行個體。
C#WebService代码:
using ...
namespace WebServiceTest2
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string EchoStringMessage(object obj)
{
//do something
}
}
}