【问题标题】:Android KSOAP2 error to get valueAndroid KSOAP2 错误获取价值
【发布时间】:2013-12-10 21:42:24
【问题描述】:

我从 Web 服务获取价值时出错。我一直在尝试,但没有成功。我使用 WCF 实体框架进行了 Web 服务。这台服务器运行良好。但我想连接并从 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); 设置内容视图(R.layout.menu); button1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View 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); text1 从不设置“测试”我该怎么办。我不知道我想念什么。谢谢。 (使用Ksoap2.4)

【问题讨论】:

    标签: c# java android wcf web-services


    【解决方案1】:

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

    希望你能得到解决。

    【讨论】:

      【解决方案2】:

      我将我的网络服务放入 ISS。我的链接是 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!");
                }          
      

      【讨论】:

      • 我也无法在模拟器中连接浏览器。可能有问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多