【问题标题】:Consuming WCF service on Android using ksoap2 - Internal Server Error使用 ksoap2 在 Android 上使用 WCF 服务 - 内部服务器错误
【发布时间】:2011-12-13 16:02:56
【问题描述】:

我正在为 WCF 服务开发 Android 客户端。有一个 Windows 应用程序可以与该服务一起使用,没有任何问题。但是,当我尝试使用 kSoap2 在 Android 上使用该服务时 - 我收到 500 Internal Server Error。显然我做错了什么,但不知道是什么。

这是我的 Java 代码:

// SOAP consts
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SERVICE_NAME = "/SignService";
private static final String SOAP_ACTION = "http://tempuri.org/ISignService/";
...
String url;
String method_name = "GetExistedSignData";

url = mServerAddress + SERVICE_NAME;

/* the connect logic goes here */
try {
    SoapObject request = new SoapObject(NAMESPACE, method_name);

    request.addProperty("displayId", "HWI_00:1E:8C:87:7F:8D");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

    envelope.dotNet = true;
    //envelope.implicitTypes = true;
    envelope.setAddAdornments(false);
    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
    androidHttpTransport.call(method_name, envelope);
    sb.append(envelope.toString() + "\n");
    SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

    //to get the data
    String resultData = result.toString();
    sb.append(resultData + "\n");
} catch (IOException e) {
    sb.append("IO Problem:\n" + e.getMessage() + "\n");
} catch (XmlPullParserException e) {
    sb.append("Parser Problem:\n" + e.getMessage() + "\n");
}
catch (Exception e) {
    sb.append("Error:\n" + e.getMessage() + "\n");
}

这里是windows客户端成功调用方法的HTTP转储:

POST /SignService HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Host: ariadnetest.ariadne.vn
Content-Length: 995
Connection: Keep-Alive

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
    <r:Sequence s:mustUnderstand="1">
    <r:Identifier>urn:uuid:b6073cc9-d142-4045-90cb-1ae8d839d400</r:Identifier>
    <r:MessageNumber>1</r:MessageNumber>
    </r:Sequence>
    <a:Action s:mustUnderstand="1">http://tempuri.org/ISignService/GetExistedSignData</a:Action>
    <a:MessageID>urn:uuid:ad89a2da-6205-460b-b50c-9b354d83594d</a:MessageID>
    <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="9c91571d-e363-45da-ab5b-a83d48f3ec82">468b8556-f549-4d1f-969a-591aae05d4af</ActivityId>
    <a:ReplyTo>
    <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">http://ariadnetest.ariadne.vn/SignService</a:To>
</s:Header>
<s:Body>
    <GetExistedSignData xmlns="http://tempuri.org/">
    <displayId>HWI_00:1E:8C:87:7F:8D</displayId>
    </GetExistedSignData>
</s:Body>
</s:Envelope>

这是我调用相同方法失败的 HTTP 转储:

POST /SignService HTTP/1.1
User-Agent: ksoap2-android/2.6.0+
Content-Type: application/soap+xml;charset=utf-8
Connection: close
Content-Length: 358
Host: ariadnetest.ariadne.vn
Accept-Encoding: gzip

<?xml version="1.0"?>
<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/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header/>
<v:Body>
    <GetExistedSignData xmlns="http://tempuri.org/">
    <displayId>HWI_00:1E:8C:87:7F:8D</displayId>
    </GetExistedSignData>
</v:Body>
</v:Envelope>

作为回报,我得到:

HTTP/1.0 500 Internal Server Error
Date: Tue, 13 Dec 2011 15:46:07 GMT
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html
Content-Length: 2114
Connection: close

错误描述中最有用的部分是:

Error Code 64: Host not available
Background: The connection to the  Web server was lost.

我对 WCF 和 .NET 不是很熟悉,所以对于可能出现的问题我没有选择。我没有开发我需要在 Android 中使用的 WCF 服务。

【问题讨论】:

    标签: android .net wcf soap ksoap2


    【解决方案1】:

    我认为这行是错误的:

    androidHttpTransport.call(method_name, envelope);
    

    第一个参数应该是:NAMESPACE + METHOD_NAME

    【讨论】:

    • 没有任何区别。根据 kSoap2 文档,第一个参数用于设置“soapAction”标头字段,该字段在 SOAP 1.2 中没有使用
    【解决方案2】:

    如果您有选择,最好不要在 Android 上使用 SOAP。 SOAP 比 REST 复杂得多,并且需要一个复杂的框架,至少目前是 Android 不可用的。

    【讨论】:

    • 还有哪些选择?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多