繁体   English   中英

在Android上连接到WCF Web服务/ 415错误

[英]Connect to WCF WebService on Android / 415 error

我想连接到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。

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

我有同样的问题,通过在WCF服务的端点配置上将WsHttpBinding更改为basicHttpBinding来解决

这或许可以帮助你做出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端或Intenet Conncetion

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM