我在尝试使用 kSOAP2 在 Android 中使用 ColdFusion SOAP 服务时遇到问题。这是我的 java 代码,用于调用我在 ColdFusion 中编写的测试方法(它只返回一个字符串):
private static final String NAMESPACE = "http://www.sub.tv/MyService.cfc?WSDL";
private static String URL = "http://www.sub.tv/MyService.cfc";
private static final String METHOD_NAME = "TestMethod";
private static final String SOAP_ACTION = "http://www.sub.tv/MyService.cfc?method=TestMethod";
public void GetData() {
SoapPrimitive resultstring = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo inputArgs = new PropertyInfo();
inputArgs.setName("ID");
inputArgs.setValue(1234);
inputArgs.setType(Integer.class);
request.addProperty(inputArgs);
SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapenvelope.dotNet = false;
soapenvelope.setOutputSoapObject(request);
AndroidHttpTransport httptransport = new AndroidHttpTransport(URL);
//httptransport.debug = true;
try {
httptransport.call(SOAP_ACTION, soapenvelope);
resultstring = (SoapPrimitive) soapenvelope.getResponse();
} catch (Exception e) {
Log.d(DEBUG, e.getMessage());
}
}
这是我编写的 ColdFusion 测试方法,它只返回一个字符串:
<cfcomponent displayname="test_web_service" namespace="http://www.sub.tv">
<cffunction name="TestMethod" returnType = "string" access="remote" description="Test Method">
<cfargument name="ID" type="numeric">
<cfreturn "hello" />
</cffunction>
</cfcomponent>
执行上述 Java 代码时出现的错误如下:
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@2:44 in java.io.InputStreamReader@40ff5440)
我怀疑问题的原因可能是我在 SOAP_ACTION 中指定的 URL,但据我所知,这是调用 ColdFusion SOAP Web 服务方法的正确方法。在浏览器中执行该 URL 会返回预期结果。我尝试在该 URL 的查询字符串中排除方法调用,但我仍然得到相同的错误。
任何帮助将非常感激。
谢谢你的时间,
托尼