首页 文章

Android KSOAP2错误获取 Value

提问于
浏览
0

我有错误从Web服务获得 Value . 我一直在尝试,但没有成功 . 我使用WCF,Entity框架进行了webservice . 这台服务器运行良好 . 但我想从Android手机连接并获得 Value .

我的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”;
protected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);的setContentView(R.layout.menu); button1.setOnClickListener(new View.OnClickListener(){@Override public void onClick(View v){SoapObject request = new SoapObject(NAMESPACE,METHODNAME);
request.addProperty( “值”,1);

SoapSerializationEnvelope sp = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sp.dotNet = TRUE;
sp.setOutputSoapObject(请求);

HttpTransportSE aht = new HttpTransportSE(URL);
aht.debug = true;
text2.setText(aht.toString());
// AndroidHttpTransport aht = new AndroidHttpTransport(URL);
尝试{
aht.call(SOAPACTION,SP); //我有错误!没工作 .
// SoapPrimitive resultstring =(SoapPrimitive)sp.getResponse();
text1.setText( “测试”);
//text2.setText(resultstring.toString());
} catch(例外e){
// TODO:处理异常
text2.setText( “畑!”);
}
}
});

我得到错误aht.call(SOAPACTION,sp); text1永远不会设置“测试”我该怎么办 . 我不知道我想念的是什么 . 谢谢 . (使用Ksoap2.4)

2 回答

  • 0

    试试这个例子,或者用这段代码检查你的代码
    http://www.c-sharpcorner.com/uploadfile/88b6e5/how-to-call-web-service-in-android-using-soap/

    希望你能得到解决方案 .

  • 0

    我将我的网络服务放入国际空间站 . 我的链接是http:// localhost: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!");
              }
    

相关问题