ksoap2 - 始终缺少请求参数

时间:2010-12-22 16:38:52

标签: android ksoap2

我有一个ASP.Net网络服务,可以完全通过iPhone SOAP代码或其他.Net客户端调用。但是,当我尝试使用Ksoap2时,未设置传递给服务的参数。在服务中,参数“AuthenticationID”不能进入,因为WebMethod做的第一件事是检查字符串是否为空或返回“AuthenticationFailure”响应。我得到了那个响应所以我知道SOAP的东西很好,只是参数没有被传递。

public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
      request.addProperty("AuthenticationID", "5");       
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope.dotNet = true;
      envelope.setOutputSoapObject(request);  
      HttpTransportSE httpTransport = new HttpTransportSE(URL);  
      httpTransport.debug = true;  
      httpTransport.call(SOAP_ACTION, envelope); 
      SoapObject result=(SoapObject)envelope.getResponse(); 
      return result;
  }

WSDL看起来如下:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <LookupStores xmlns="http://blah.com/Services/">
          <AuthenticationID>string</AuthenticationID>
          <NameMatch>string</NameMatch>
        </LookupStores>
      </soap:Body>
    </soap:Envelope>

请给我一些尝试,这只是一个简单的服务,我认为使用KSoap2很容易消费。 谢谢!

2 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,并设法通过使用PropertyInfo传递我的参数。尝试下面的代码,没有保证它会起作用,但值得一试。

public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException 
{
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    PropertyInfo pi = new PropertyInfo();
    pi.setName("int"); //change to appropriate type e.g. String
    pi.setValue(5); // if sString add the speech marks e.g. "5"
    pi.setType("AuthenticationID".getClass());                  
    request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);  
    HttpTransportSE httpTransport = new HttpTransportSE(URL);  
    httpTransport.debug = true;  
    httpTransport.call(SOAP_ACTION, envelope); 
    SoapObject result=(SoapObject)envelope.getResponse(); 
    return result;
}  

希望这有帮助。

答案 1 :(得分:0)

您需要检查的第一件事是WebService和Android应用程序中的命名空间字符串是完全相同的