【问题标题】:Connect to WCF WebService on Android / 415 error连接到 Android 上的 WCF WebService / 415 错误
【发布时间】:2013-04-08 14:34:43
【问题描述】:

我想在 Android 项目上连接到我的 WCF WebService。我跟着教程

http://javatutorialspoint.blogspot.com/2012/02/android-web-service-access-using-ksoap2.html

但我收到 415 错误。也许还有其他简单的连接方式?或者我应该修复什么?

04-16 10:57:10.675: E/WS(4858): java.io.IOException: HTTP 请求 失败,HTTP 状态:415

这是我的网络服务的网址(它是本地的)http://hq.fs.com.pl:8090/fs/Integrator

活动

package com.example.fs;

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

import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;

public class AndroidWSClientActivity extends Activity {

    //private static final String SOAP_ACTION = "http://ws.android.com/sayHello";
    //private static final String METHOD_NAME = "sayHello";
    //private static final String NAMESPACE = "http://ws.android.com/";
    //private static final String URL = "http://175.157.229.119:8080/AndroidWSTest/services/PrintMsg?wsdl";

    // WS
    private static final String SOAP_ACTION = "http://tempuri.org/IntegratorMethods/GetAddonsTypes";
    private static final String METHOD_NAME = "GetAddonsTypes";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://hq.fs.com:8090/fs/Integrator?wsdl";

    TextView textView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wsclient_page);

    textView = (TextView) findViewById(R.id.textView2);


    Thread networkThread = new Thread() {
        @Override
        public void run() {
          try {
             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);         
             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.setOutputSoapObject(request);

             HttpTransportSE ht = new HttpTransportSE(URL);
             ht.call(SOAP_ACTION, envelope);
             final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
             final String str = response.toString();

             runOnUiThread (new Runnable(){ 
         public void run() {
             textView.setText(str);
               }
           });
          }
         catch (Exception e) {
            Log.e("WS", e.toString());
         }
        }
      };
      networkThread.start();
      }
}

更新

我使用 chrome://soaclient/content/webservices.xul 检查了我与 WebService 的连接,一切看起来都很好。我有操作:GetAddonsTypes 和状态:200 OK。

【问题讨论】:

  • 我将我的 Soap 版本更改为 .VER12 并收到 500 错误。我的 WCF 服务正在使用自定义 Soap 11 版本。

标签: java android web-services


【解决方案1】:

我是一名中国开发者,所以我的英语很差。 我有同样的问题,通过将 SoapEnvelope.VER12 更改为 SoapEnvelope.VER10 解决了它。 问题解决了,但是不知道为什么。 我的 wsdl 文件是 xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 所以版本应该是 12,而不是 10。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,通过在 WCF 服务的端点配置上将 WsHttpBinding 更改为 basicHttpBinding 解决了这个问题

    【讨论】:

      【解决方案3】:

      这可能会帮助你让Request

      private static final String URL =
      "http://give Here Server Ipaddress/AndroidWSTest/services/PrintMsg?wsl";
      

      表示提供当前更新ipaddress 还要确保你的路过

      (NAMESPACE, METHOD_NAME)
      

      正确并与webServie 匹配Method nameNamespace 还检查Intenet Conncetionwebservice 工作正常Server 侧或不是

      【讨论】:

      • 我认为这与错误的 URL 无关。我说我遵循教程,但是 WebService 是用 WCF 创建的(不像教程中的 Axis2)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多