gpt4 book ai didi

.net - 尝试将 Android 应用程序连接到 .NET ".svc"Web 服务和服务器响应不支持媒体类型

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:12 25 4
gpt4 key购买 nike

我正在尝试将 Android 应用程序连接到具有 .svc 扩展名的 Axapta 网络服务。我正在使用具有所有依赖项的 Ksoap 2.5.4 jar。以下是代码。我无法连接到网络服务,因为响应转储表明服务器不支持该媒体类型。


网络服务:

从 Windows Phone 连接时正常启动并运行


代码:

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;

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);
}
}
}

请求转储 :

<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>

响应转储:

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

注意:我已经更新了代码,因为我发现 web-service 是 Soap 版本 1.2。

最佳答案

我认为当前的问题出在 URL 中。服务的 URL 不是:

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

这是服务描述(WSDL 文件)的 URL,它只接受 HTTP GET 请求(所有对 WCF 服务的 SOAP 请求都是 HTTP POST)。您的评论请求表明您正在尝试向此 URL 发送请求 - 它总是会失败。服务的 URL 没有 ?wsdl 查询字符串:

http://192.168.100.188/MicrosoftDynamicsAXAif50/localendpointservice.svc

关于.net - 尝试将 Android 应用程序连接到 .NET ".svc"Web 服务和服务器响应不支持媒体类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6215480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com