开发者

Trying to connect Android App to .NET ".svc" webservice and server responds Media type not supported

开发者 https://www.devze.com 2023-03-10 03:58 出处:网络
I am trying to connect Android App to Axapta web-service which is having .svc extension. I am using Ksoap 2.5.4 jar with all dependencies. Following is the code.

I am trying to connect Android App to Axapta web-service which is having .svc extension. I am using Ksoap 2.5.4 jar with all dependencies. Following is the code. I could not connect to web-service because response dump indicates that media type not supported by server.


Web Service :

Up and running properly while connecting from Windows Phone


Code :

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 org.ksoap2.transport.ServiceConnection;

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

public class SoapActivity extends Activity {
     private static String mSOAPACTION="http://schemas.microsoft.com/dynamics/2008/01/services/LocalEndpointService/read",
                           mOPERATIONNAME="read",
                           WSDL_TARGET_NAMESPACE = "http://schemas.microsoft.com/dynamics/2008/01/services/";

     private static String mNAMESPACE="http://schemas.microsoft.com/dynamics/2008/01/services/";
     private static String mMETHODNAME="read";
     private static String mURL="http://192.168.100.188/MicrosoftDynamicsAXAif50/localendpointservice.svc?wsdl";
     private SoapPrimitive result = null;
     public static Context context=null;
     private HttpTransportSE  httpTransportSE = null;
     private TextView tv = null;

  开发者_StackOverflow   public void onCreate(Bundle savedInstanceState){
     SoapSerializationEnvelope envelope = null;
     SoapObject Request = null;
     ServiceConnection sc = null;
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     tv = (TextView)findViewById(R.id.tv);
     try {
         envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
         envelope.setAddAdornments(false);
         envelope.encodingStyle = SoapSerializationEnvelope.ENC;
         envelope.env=SoapSerializationEnvelope.ENV;
         envelope.implicitTypes = true;
         Request = new SoapObject(mNAMESPACE, mMETHODNAME);
         //Request = new SoapObject(mNAMESPACE, mOPERATIONNAME);         
         //Request.addProperty("LocalEndpointServiceReadRequest", "Qing");       
         envelope.dotNet = true;
         envelope.setOutputSoapObject(Request);      
         //envelope.addMapping(mNAMESPACE, "UserCredentials",new UserCredendtials().getClass());
         /*androidHttpTransport = new AndroidHttpTransport(mURL);
         androidHttpTransport.debug = true;
         androidHttpTransport.call(mSOAPACTION, envelope);*/

         httpTransportSE = new HttpTransportSE(mURL);
         /*sc = httpTransportSE.getConnection();
         if(sc!=null){
             sc.setRequestProperty("Content-Type", "text/xml");
         }else{
             Log.i(getClass().getSimpleName(),"SC : null.");
         }*/

         httpTransportSE.debug = true;
         //httpTransportSE.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
         httpTransportSE.call(mSOAPACTION, envelope);
         Object response = envelope.getResponse();
         tv.setText(response.toString());
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }finally{
             Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump);
             Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump);
        }
    }
}

requestDump :

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:d="http://www.w3.org/2001/XMLSchema" 
            xmlns:c="http://www.w3.org/2001/12/soap-encoding" 
            xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
  <v:Header />
  <v:Body>
    <read xmlns="http://schemas.microsoft.com/dynamics/2008/01/services/" />
  </v:Body>
</v:Envelope>

responseDump :

The server cannot service the request because the media type is unsupported.

Note : I have updated the code because I have found that web-service is of Soap version 1.2.


I think that current problem is in the URL. URL of the service is not:

http://192.168.100.188/MicrosoftDynamicsAXAif50/localendpointservice.svc?wsdl

That is URL to service description (WSDL file) which accepts only HTTP GET requests (all SOAP requests to WCF service are HTTP POST). Your request from comment shows that you are trying to POST request to this URL - it will always fail. The URL of the service is without ?wsdl query string:

http://192.168.100.188/MicrosoftDynamicsAXAif50/localendpointservice.svc
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号