0

我有一个 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 很容易使用。谢谢!

4

2 回答 2

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;
}  

希望这可以帮助。

于 2010-12-23T01:36:30.037 回答
0

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

于 2012-02-10T21:25:46.787 回答