2013-07-15 120 views
-1

我想從soap webservice得到響應,但總是出現錯誤,請檢查我是否正確調用web服務。 以下是我的web在android中訪問soap web服務

<wsdl:definitions name="MobileeServiceWsd" targetNamespace="urn:MobileeServiceWsd"><wsdl:import location="http://vddp.dewa.gov.ae:50700/MobileeService/Config2/bindings?wsdl&style=document" namespace="urn:MobileeServiceWsd/Config2/document"/><wsdl:service name="MobileeService"><wsdl:port name="Config2Port_Document" binding="bns0:Config2Binding"><soap:address location="http://vddp.dewa.gov.ae:50700/MobileeService/Config2?style=document"/></wsdl:port></wsdl:service></wsdl:definitions> 

的WSDL和下面是我的代碼。

private static final String METHOD_NAME = "getOutstandingBalance"; 
    private static final String SOAP_ACTION = "MobileeService"; 
    private static final String NAMESPACE = "MobileeServiceWsd/Config2/document"; 
    private static final String URL = "http://vddp.dewa.gov.ae:50700/MobileeService/Config2/bindings?wsdl&style=document"; 


    public SoapObject testMethod(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException 
    { 
     //List<HeaderProperty> headers = new ArrayList<HeaderProperty>(); 

     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet = true; //for .net services 
     envelope.bodyOut = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:MobileeServiceVi\">"+ 
        "<soapenv:Header/>"+ 
        "<soapenv:Body>"+ 
         "<urn:getOutstandingBalance>"+ 
         "<urn:contractaccount>000001000104</urn:contractaccount>"+ 
         "<urn:mobileosver>ios 4.3</urn:mobileosver>"+ 
        "<urn:appver>3.3</urn:appver>"+ 
         "<urn:appidentifier>343534</urn:appidentifier>"+ 
         "</urn:getOutstandingBalance>"+ 
        "</soapenv:Body>"+ 
       "</soapenv:Envelope>"; 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE httpTransport = new HttpTransportSE(URL); 

     //httpTransport.call(SOAP_ACTION, envelope, headers); 
     httpTransport.call(SOAP_ACTION, envelope); 

     return (SoapObject) envelope.getResponse(); 
    } 

回答

0
Using Ksoap2 library and write .net web service 
Sucessful Connection with Asp.net Webservice----- 
package ProductVerificationCard.in; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 

public class AdminLogin extends Activity { 
    /** Called when the activity is first created. */ 
    Button btn_ok; 
    TextView textView; 
    private static final String SOAP_ACTION = "http://tempuri.org/Login"; 

    private static final String OPERATION_NAME = "Login"; 

    private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/"; 

    private static final String SOAP_ADDRESS = "http://10.0.2.2/new/WebService.asmx"; 
    String s; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     btn_ok=(Button) findViewById(R.id.btn_login); 
     textView=(TextView) findViewById(R.id.tv_error); 

     btn_ok.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, 
         OPERATION_NAME); 

         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
         SoapEnvelope.VER11); 
         envelope.dotNet = true; 

         envelope.setOutputSoapObject(request); 

         HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 

         try 

         { 

         httpTransport.call(SOAP_ACTION, envelope); 

         Object response = envelope.getResponse(); 

         //textView.setText(response.toString()); 
         s=response.toString(); 
         if(s=="true") 
         { 
          Intent intent=new Intent(AdminLogin.this,MenuForm.class); 
           startActivity(intent); 

         } 

         else 
         { 
          textView.setText("Enter Valid Username or Password"); 
         } 
         } 

         catch (Exception exception) 

         { 

         textView.setText(exception.toString()); 

         } 
       // TODO Auto-generated method stub 
       } 
     }); 

    } 
} 
+0

以及如何,這是從問題的代碼有什麼不同? – Selvin

+0

以下鏈接適用於我https://groups.google.com/forum/#!topic/android-developers/sNwGyt9gHso –