Ksoap2 是否要求 Web 服务生成 wsdl?

发布于 2024-12-08 14:31:10 字数 1798 浏览 0 评论 0原文

我已经成功编写了一个 Android 应用程序,它使用 Ksoap2 调用 asp.net Web 服务。我现在想要迁移应用程序以使用 PHP Web 服务。我已成功将 Web 服务迁移到本机 PHP Web 服务(并使用 PHP 客户端对其进行了测试),但在使用 KSOAP 调用它时遇到了问题。令我震惊的一个想法是,原生 PHP Web 服务不是使用 wsdl 生成的,并且无法自动生成 wsdl。 ksoap2 是否需要 wsdl 才能成功调用 Web 服务方法?

asp.net Web 服务位于 http://mycomputer/AlumLocateService/Service.asmx

调用 asp.net 服务:

private static final String NAMESPACE = "http://mycomputer/";
private static final String URL = "http://mycomputer/AlumLocateService/Service.asmx";
private static final String METHOD_NAME_3 = "FindCloseDetails";
private static final String SOAP_ACTION_3  = NAMESPACE + METHOD_NAME_3;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_3);
PropertyInfo pi = new PropertyInfo();
pi.setName("userid");
pi.setValue(userid);
pi.setType(string.class);
request.addProperty(pi);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

androidHttpTransport.call(SOAP_ACTION_3, envelope);

//Parse Response
Object myResult = envelope.bodyIn;
SoapObject resultsRequestSOAP = (SoapObject) myResult;
String[] results = getStringArrayResponse(resultsRequestSOAP, null);
return results;

PHP 服务位于 http://mycomputer/PHPTest/testserver.php 并复制 asp.net Web 服务的方法。我希望我需要做的就是更改以下内容

private static final String URL = "http://mycomputer/PHPTest/testserver.php"; 

并删除该行,

envelope.dotNet = true;

但是当我这样做时,当 androidHttpTransport.call(SOAP_ACTION_3, 信封) 进行呼叫。

I have successfully written an Android app which calls an asp.net web service using Ksoap2. I now want to migrate the app to use a PHP web service. I have successfully migrated the web service over to a native PHP web service (and tested it using a PHP client) but I'm having trouble calling it using KSOAP. One thought that struck me was that the native PHP web service was not generated using a wsdl, and is not able to automatically generate a wsdl.
Does ksoap2 require a wsdl to successfully call a web service method?

The asp.net web service is located at http://mycomputer/AlumLocateService/Service.asmx

For the succesful call to asp.net service:

private static final String NAMESPACE = "http://mycomputer/";
private static final String URL = "http://mycomputer/AlumLocateService/Service.asmx";
private static final String METHOD_NAME_3 = "FindCloseDetails";
private static final String SOAP_ACTION_3  = NAMESPACE + METHOD_NAME_3;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_3);
PropertyInfo pi = new PropertyInfo();
pi.setName("userid");
pi.setValue(userid);
pi.setType(string.class);
request.addProperty(pi);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

androidHttpTransport.call(SOAP_ACTION_3, envelope);

//Parse Response
Object myResult = envelope.bodyIn;
SoapObject resultsRequestSOAP = (SoapObject) myResult;
String[] results = getStringArrayResponse(resultsRequestSOAP, null);
return results;

The PHP service is located at http://mycomputer/PHPTest/testserver.php and replicates the methods of the asp.net web service. I had hoped thta all I woudl need to do would be to change the following

private static final String URL = "http://mycomputer/PHPTest/testserver.php"; 

and remove the line

envelope.dotNet = true;

but when I do that i get "XmlPullParserException: unexpected type (position END_DOCUMENT null...." when the androidHttpTransport.call(SOAP_ACTION_3, envelope) call is made.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-12-15 14:31:11

我已经更改为使用 PHP Zend_Soap_Server 我必须将 Android 代码的最后一部分更改为:

Object myResult = envelope.getResponse();
String[] results = null;
if (myResult instanceof Vector)
{
    Vector<Object> myVector = (Vector<Object>) myResult;

results = new String[myVector.size()];

for (int i = 0; i< myVector.size();i++){

    results[i] = myVector.elementAt(i).toString();
}
} 

return results;

One I had changed to using a PHP Zend_Soap_Server I had to change the last part of my Android code to:

Object myResult = envelope.getResponse();
String[] results = null;
if (myResult instanceof Vector)
{
    Vector<Object> myVector = (Vector<Object>) myResult;

results = new String[myVector.size()];

for (int i = 0; i< myVector.size();i++){

    results[i] = myVector.elementAt(i).toString();
}
} 

return results;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文