【问题标题】:call webservice in android with ksoap使用 ksoap 在 android 中调用 webservice
【发布时间】:2018-02-22 14:00:53
【问题描述】:

我使用 Visual Studio 2010 创建 wcf 并在 webmaterix 3 上发布...... 我在 android 应用程序中调用这个 web 服务但没有运行...... 这是我的 web.config:

<?xml version="1.0"?>
<configuration>
<system.web>
  <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
  <behaviors>
  <serviceBehaviors>
    <behavior>

       <serviceMetadata httpGetEnabled="true"/>

      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
 <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>

这是我的安卓代码:

   private static final String NAMESPACE = "http://tempuri.org/";
            private static final String URL = 
                "http://localhost:60977/Service1.svc?singleWsdl";   
  private static final String SOAP_ACTION =     "http://tempuri.org/IService1/GetData";
            private static final String METHOD_NAME = "GetData";
             TextView txt=(TextView)findViewById(R.id.textView1);
        SoapObject request = new SoapObject(NAMESPACE,      METHOD_NAME);       
    SoapSerializationEnvelope envelope = 
        new    SoapSerializationEnvelope(SoapEnvelope.VER11); 

                envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new    HttpTransportSE(URL);
                name("SS");
                try {
                    name("0");
            androidHttpTransport.call(SOAP_ACTION, envelope);
                    name("1");
        SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
                    name("2");
                    name(resultsRequestSOAP.toString());
                    name("3");
            txt.setText("Received :" + resultsRequestSOAP.toString());

                } catch (Exception e) {
                    txt.setText(e.getMessage());
                    name(e.getMessage());
                    e.printStackTrace();
                }

当 catch 运行时,没有任何消息...

【问题讨论】:

标签: android web-services


【解决方案1】:
【解决方案2】:
 private static final String URL = 
                "http://localhost:60977/Service1.svc?singleWsdl"; 
            private static final String METHOD_NAME = "GetData";
    final String SOAP_ACTION = "http://tempuri.org/GetData";                  

                       try {
                           SoapObject request = new SoapObject(WebServiceUtil.NAMESPACE, METHOD_NAME);
                           SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                           envelope.dotNet = true;                        
                           envelope.setOutputSoapObject(request);

                           HttpTransportSE androidHttpTransport = new HttpTransportSE(WebServiceUtil.URL);
                           Log.d("URL  :: ", WebServiceUtil.URL);           
                           androidHttpTransport.call(SOAP_ACTION, envelope);


                       }
                       catch (Exception e) {
                            e.printStackTrace();

                       }

                }

【讨论】:

    【解决方案3】:

    实际上,这里的 localhost 本身就是模拟器,因为代码在模拟器中运行。所以你应该连接到 10.0.2.2。有关更多详细信息,请参阅 Android Emulator Networking 并且不要忘记清单文件中的网络权限

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      相关资源
      最近更新 更多