我遇到了一个问题,试图使用安卓中的ColdFusion SOAP服务使用kSOAP2。下面是我用ColdFusion编写的调用测试方法的java代码(它只返回一个字符串):
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服务方法的正确方法。在浏览器中执行该URL将返回预期的结果。我尝试将方法调用排除在该URL的查询字符串中,但仍然得到相同的错误。
任何帮助都将不胜感激。
耽误您时间,实在对不起,
托尼
发布于 2013-01-15 13:57:55
尝试删除显示名称和命名空间。我知道在通过CFML公开web服务时,这两种方法都不需要。我也怀疑你有一个错误,你没有看到。注意,在您的错误中,它具有:
org.xmlpull...(position:START_TAG @2:44 in java.io.InputStreamReader@40ff5440)
这个html标签告诉我,您的web服务正在抛出一个错误。当CF这样做时,它会输出HTML。知道了这一点,这里有一些建议。从浏览器:
1)在浏览器中直接访问您的服务:http://www.sub.tv/MyService.cfc。登录到CF管理,并确保您看到您的CFC的文档。
2)访问WSDL:http://www.sub.tv/MyService.cfc?wsdl。您应该看到您的各种功能公开了。
3)访问您的测试功能:http://www.sub.tv/MyService.cfc?method=TestMethod&id=123
实际上,由于www.sub.tv是公共的,而且MyService.cfc是可用的,所以我为您测试了上述所有内容,看起来您的CFC很好,不会抛出错误。
我对你的CFC做了个快速测试:
<cfset test = CreateObject("WebService", "http://www.sub.tv/MyService.cfc?WSDL") />
<cfdump var="#test.TestMethod(123)#" />这将输出"hello",如果Web服务运行正常,这就是您所期望的。这对我来说是个问题,你怎么用Android来称呼它。我在Java中对Web服务所做的工作并不多,所以在这里我只能提供如此多的帮助。
但是,我注意到您的WSDL将测试方法参数定义为Double。这对于CF来说是正常的,因为数字类型可以容纳任何类型的数字。但是,上面的示例代码显示了以下内容:
inputArgs.setType(Integer.class); 尝试将其更改为Double.class (或任何在Java中应该是匹配参数类型的内容)。
这就是我给你的全部。祝好运!
发布于 2013-01-15 14:21:38
我怀疑问题在于您正在通过SOAP调用web服务,但是响应不是预期的格式(XML)。如果您查看web服务调用http://www.sub.tv/MyService.cfc?method=TestMethod&id=123生成的输出,就会看到以下内容:
<wddxPacket version='1.0'>
<header/>
<data>
<string>hello</string>
</data>
</wddxPacket>这是因为在默认情况下,ColdFusion将所有返回类型(包括简单的返回类型)序列化为WDDX格式,但XML除外.从这里的CFFunction文档
尝试在您的returnType函数中指定XML的returnType,并查看它是否有效。您可能仍然需要调整输出以获得kSOAP所期望的结果。我不知道它想要的XML格式,但这应该会让您开始。
将CFFunction更改为如下所示:
<cffunction name="TestMethod" returnType="xml" access="remote" description="Test Method">
<cfargument name="ID" type="numeric">
<cfset var xml = "">
<cfxml variable="xml">
<test>hello</test>
</cfxml>
<cfreturn xml>
</cffunction>https://stackoverflow.com/questions/14335923
复制相似问题