java - 连接到 Android/415 错误上的 WCF WebService

标签 java android web-services

我想连接到 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 request failed, HTTP status: 415

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

Activity

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。

最佳答案

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

关于java - 连接到 Android/415 错误上的 WCF WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16032799/

相关文章:

java - A.super.foo() 在 Defender 方法 (Java 8) 中如何工作?

java - 登录远程 Windows 服务器并执行 .bat 文件

javascript - 为 TokBox Webrtc session 添加白板功能

android - SwipeRefreshLayout 出错,无法在第一时间刷新(加载更多)

jquery - 当 jQuery 的 .ajax 调用时,需要在服务器端异步执行 Web 服务

iPhone 的 PHP RESTful Web 服务

java - 共享首选项 - 它们存在多久以及用户可以编辑它们吗?

java - 如何从自定义 ArrayList 中获取特定条目?

java - 如何检测超声波?

java - ECONNREFUSED(连接被拒绝)android连接到webservice