2013-11-25 61 views
0

我有錯誤從Web服務獲取價值。我嘗試所有的時間,但沒有成功。我用WCF,Entity框架做了webservice。這臺服務器很好用。但我想連接並從Android手機獲得價值。Android KSOAP2出錯獲取值

我的Android代碼:

private final String NAMESPACE="http://tempuri.org/"; 
private final String SOAPACTION="http://tempuri.org/IService/GetValues"; 
private final String METHODNAME="GetTreatmentValues"; 

private final String URL="http://localhost:49674/Service.svc"; 

保護無效的onCreate(捆綁savedInstanceState){
super.onCreate(savedInstanceState); setContentView(R.layout.menu); button1.setOnClickListener(新View.OnClickListener(){

@覆蓋
公共無效的onClick(視圖v){

  SoapObject request = new SoapObject(NAMESPACE,METHODNAME); 
      request.addProperty("value",1); 

      SoapSerializationEnvelope sp = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      sp.dotNet=true; 
      sp.setOutputSoapObject(request); 

      HttpTransportSE aht = new HttpTransportSE(URL); 
      aht.debug = true; 
      text2.setText(aht.toString()); 
      //AndroidHttpTransport aht = new AndroidHttpTransport(URL); 
      try { 
       aht.call(SOAPACTION,sp); //I have ERROR! no work. 
       //SoapPrimitive resultstring = (SoapPrimitive)sp.getResponse(); 
       text1.setText("test"); 
       //text2.setText(resultstring.toString()); 
      } catch (Exception e) { 
       // TODO: handle exception 
       text2.setText("hata!"); 
      }   
        }  
      }); 

我得到錯誤aht.call(SOAPACTION,SP); (使用Ksoap2.4)

回答

0

我把我的webservice放入ISS。我的鏈接爲http://本地主機:90/Service.svc WSDL 在此頁面中,我看到的XML代碼

-<wsdl:binding name="BasicHttpBinding_IService" type="tns:IService"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> 
    wsdl:operation name="GetTreatmentValues"> 

    <soap:operation style="document" 
    soapAction="http://tempuri.org/IService/GetTreatmentValues"/> 


    -<wsdl:input> 

    <soap:body use="literal"/> 

    </wsdl:input> 

    -<wsdl:output> 

    <soap:body use="literal"/> 

    </wsdl:output> 

    </wsdl:operation> 

我寫這篇文章的代碼到Android應用

private final String NAMESPACE="http://tempuri.org/"; 
private final String SOAPACTION="http://tempuri.org/GetTreatmentValues"; 
private final String METHODNAME="GetTreatmentValues"; 


private final String URL="http://localhost:90/Service.svc?singleWsdl"; 

,但我拿到永諾?錯誤在這裏(:(

try { 
       aht.call(SOAPACTION,sp); //I have ERROR! no work. 
       //SoapPrimitive resultstring = (SoapPrimitive)sp.getResponse(); 
       text1.setText("test"); 
       //text2.setText(resultstring.toString()); 
      } catch (Exception e) { 
       // TODO: handle exception 
       text2.setText("hata!"); 
      }   
+0

我也無法連接模擬器中的瀏覽器。它可能是問題? –