KSoap2 SoapObject Object Reference not set to an instance

后端 未结 4 1050
时光取名叫无心
时光取名叫无心 2020-12-21 05:17

I think this is a simple problem that others may be able to provide the missing link to. I have a Workflow wcf service that my .NET clients can communicate with pro

相关标签:
4条回答
  • 2020-12-21 05:49

    I know its too late to answer this but I faced the same problem and the problem in my code was that I typed the property.setname() incorrect .. make sure you wrote the correct name of the method parameter (copy past it from the wsdl) I'm using ksoap2 3.1.1 btw!

    0 讨论(0)
  • 2020-12-21 05:57

    Change the following:

    SoapObject response = (SoapObject)envelope.getResponse();
      X = response.getProperty(0).toString();
    

    to be:

    SoapObject response = (SoapObject)envelope.bodyIn;
                    if(response != null)
                    {
                          X=response.getProperty(0).toString();
                    }
    
    0 讨论(0)
  • 2020-12-21 05:58

    I am using below function in my class to work with SOAP Web-Service.

    public static String DeleteGame(String GameIDValue, String PlayerIdValue) {
    
            String responce = null; 
    
            SoapObject request = new SoapObject(SOAP_NAMESPACE, SOAP_METHOD_DeleteGame);
    
            PropertyInfo GameId = new PropertyInfo();
            PropertyInfo PlayerId = new PropertyInfo();
    
            GameId.setName("gameid");
            GameId.setValue(GameIDValue);
    
            PlayerId.setName("PlayerID");
            PlayerId.setValue(PlayerIdValue);
    
            request.addProperty(GameId);
            request.addProperty(PlayerId);
    
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE aht = new HttpTransportSE(SOAP_URL);
            try {
                aht.call(SOAP_ACTION_DeleteGame, envelope);
                SoapPrimitive LoginResult;
                LoginResult = (SoapPrimitive)envelope.getResponse();
                System.out.println("=================Delete Game Results: "+LoginResult.toString());
                //System.out.println(LoginResult.toString());
                responce = LoginResult.toString();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
    
            return responce;
        }
    
    0 讨论(0)
  • 2020-12-21 06:06

    This was the class that i am using for calling web service hope this might help you

    public class CallSOAP {
    
    private String SOAP_ACTION="your action url";
    private String OPERATION_NAME="";//The web method OR web service you are going to call
    private final String WSDL_TARGET_NAMESPACE=SOAP_ACTION;
    private  final String SOAP_ADDRESS=Configuration.WEB_SERVICE_URL;//ip-address of serever where you host your service 
    private Exception exception;
    private String ErrorMsg="";
    private String TERST_URL="" ;
    public Object call(String MethodeName,ArrayList<PropertyInfo> Parameters){
      this.OPERATION_NAME=MethodeName;
      SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
     if(Parameters != null && Parameters.size()>0){
       for(PropertyInfo propertyInfo : Parameters){
          request.addProperty(propertyInfo);
     }
    }
    
    SoapSerializationEnvelope  envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet= true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE httpTransport =null;
    if(!this.TERST_URL.equals(""))
      httpTransport = new HttpTransportSE(this.TERST_URL);
    else
      httpTransport = new HttpTransportSE(SOAP_ADDRESS);
     Object Response =null;
     try{
        httpTransport.call(SOAP_ACTION+OPERATION_NAME, envelope);
        Response=envelope.getResponse();
      }
     catch (SocketTimeoutException ex) {
         this.ErrorMsg="Unable to connect";
          Response=null;
         this.exception=ex;
      }
      catch (IOException ie) {
       this.ErrorMsg="Unable to connect";
      Response=null;
       this.exception=ie;
      }
       catch (Exception e) {
        this.ErrorMsg="Unable to connect";
        Response=null;
        this.exception=e;
     }
          return Response;
       }
    }
    
    0 讨论(0)
提交回复
热议问题