2013-04-16 61 views
0

我想連接到我的WCF WebService Android項目。我按照教程連接到Android/415錯誤的WCF WebService

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

但我得到415錯誤。也許有其他簡單的方法來連接?或者我應該修理一些東西?

10月4日至16日:57:10.675:E/WS(4858):產生java.io.IOException:HTTP請求 失敗,HTTP狀態:415

這是我的web服務的URL(這是本地)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行。

+0

更改我的香皂版本.VER12並得到500錯誤。我的WCF服務正在使用自定義Soap 11版本。 – boski

回答

2

我是中國人開發的端點配置改變的wsHttpBinding到basicHttpBinding的解決了這個問題,所以我的英語很差。 我有同樣的問題,通過將SoapEnvelope.VER12更改爲SoapEnvelope.VER10來解決此問題。 問題解決了,但我不知道爲什麼。 我的WSDL文件 的xmlns:SOAP12 =「http://schemas.xmlsoap.org/wsdl/soap12/」 所以版本應該是12,不是10

0

這或許可以幫助你做出Request

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

手段給當前的更新ipaddress 還請確保您的傳球

(NAMESPACE, METHOD_NAME) 

是正確的,並配以webServieMethod nameNamespace還要檢查Intenet Conncetionwebservice工作正常Server方或不方

+0

這不是關於我認爲錯誤的URL。我說我遵循教程,但WebService是使用WCF創建的(不像教程中的Axis2)。 – boski

1

我有同樣的問題,通過對WCF服務