gpt4 book ai didi

java - Android ksoap2 Web 服务获取 WSDL 的 XML 描述?

转载 作者:行者123 更新时间:2023-12-01 13:33:52 25 4
gpt4 key购买 nike

我正在使用 ksoap2 调用一个简单的方法,但在响应时我得到了 Web 服务的 XML 描述?该方法仅获取用户名和密码并返回用户余额。

我的代码:

public class FaraSMSActivity extends Activity {

private final String NAMESPACE = "http://farasms.com/SMSSYSTEM";
private final String URL = "http://farasms.com/webservice/v2.02.php?wsdl";
private final String SOAP_ACTION = "http://farasms.com/SMSSYSTEM#WSGETBalance__";
private final String METHOD_NAME = "WSGETBalance__";
private String TAG = "PGGURU";
private static String res;
Button b;
TextView tv;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

tv = (TextView) findViewById(R.id.tv_result);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
});
}


public void getBalance() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo usernamePI = new PropertyInfo();
usernamePI.setName("username");
usernamePI.setValue("faramobile");
usernamePI.setType(String.class);
request.addProperty(usernamePI);

PropertyInfo PasswordPI = new PropertyInfo();
PasswordPI.setName("password");
PasswordPI.setValue("09142168375");
PasswordPI.setType(String.class);
request.addProperty(PasswordPI);

//Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
//Set output SOAP object
envelope.setOutputSoapObject(request);
//Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);

//Get the response
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
res = response.toString();

} catch (Exception e) {
Log.e("1111", e.getMessage());
e.printStackTrace();
}
Log.e("2222", androidHttpTransport.responseDump);
}




private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
getBalance();
return null;
}

@Override
protected void onPostExecute(Void result) {
tv.setText(res);
}

@Override
protected void onPreExecute() {
tv.setText("Connecting...");
}

@Override
protected void onProgressUpdate(Void... values) {
}

}

}

使用这一行我可以记录结果: Log.e("2222", androidHttpTransport.responseDump);

当我使用网络浏览器浏览“farasms.com/webservice/v2.02.php?wsdl”时,它准确地显示了这一点!!!

这是结果:

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://farasms.com/SMSSYSTEM" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://farasms.com/SMSSYSTEM">
<types>
<xsd:schema targetNamespace="http://farasms.com/SMSSYSTEM">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:complexType name="authentication">
<xsd:all>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="returnCode">
<xsd:all>
<xsd:element name="msgid" type="xsd:string"/>
<xsd:element name="status" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="message">
<xsd:all>
<xsd:element name="fromNum" type="xsd:string"/>
<xsd:element name="toNum" type="xsd:string"/>
<xsd:element name="msg" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="fullmessage">
<xsd:all>
<xsd:element name="fromNum" type="xsd:string"/>
<xsd:element name="toNum" type="xsd:string"/>
<xsd:element name="msg" type="xsd:string"/>
<xsd:element name="date" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="returnCodes">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:returnCode[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="msgids">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="messages">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:message[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="fullmessages">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:fullmessage[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</types>
<message name="WSGETBalanceRequest">
<part name="authentication" type="tns:authentication"/>
<part name="username" type="xsd:string"/>
</message>
<message name="WSGETBalanceResponse">
<part name="result" type="xsd:string"/>
</message>
<message name="WSGETBalance__Request">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
</message>
<message name="WSGETBalance__Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSdoSendSMS1Request">
<part name="authentication" type="tns:authentication"/>
<part name="message" type="tns:message"/>
</message>
<message name="WSdoSendSMS1Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSdoSendSMS3Request">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="from" type="xsd:string"/>
<part name="to" type="xsd:string"/>
<part name="msg" type="xsd:string"/>
</message>
<message name="WSdoSendSMS3Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSdoSendSMS4Request">
<part name="authentication" type="tns:authentication"/>
<part name="message" type="tns:fullmessage"/>
</message>
<message name="WSdoSendSMS4Response">
<part name="result" type="xsd:string"/>
</message>
<message name="WSgetDeliveryRequest">
<part name="authentication" type="tns:authentication"/>
<part name="msgids" type="tns:msgids"/>
</message>
<message name="WSgetDeliveryResponse">
<part name="result" type="tns:returnCodes"/>
</message>
<message name="WSchangePasswordRequest">
<part name="authentication" type="tns:authentication"/>
<part name="newPassword" type="xsd:string"/>
</message>
<message name="WSchangePasswordResponse">
<part name="result" type="xsd:string"/>
</message>
<message name="WSgetMessagesRequest">
<part name="authentication" type="tns:authentication"/>
<part name="numRows" type="xsd:int"/>
</message>
<message name="WSgetMessagesResponse">
<part name="result" type="tns:messages"/>
</message>
<message name="WSgetNewMessagesRequest">
<part name="authentication" type="tns:authentication"/>
</message>
<message name="WSgetNewMessagesResponse">
<part name="result" type="tns:messages"/>
</message>
<portType name="SMSSYSTEMPortType">
<operation name="WSGETBalance">
<documentation>WSGETBalance</documentation>
<input message="tns:WSGETBalanceRequest"/>
<output message="tns:WSGETBalanceResponse"/>
</operation>
<operation name="WSGETBalance__">
<documentation>WSGETBalance__</documentation>
<input message="tns:WSGETBalance__Request"/>
<output message="tns:WSGETBalance__Response"/>
</operation>
<operation name="WSdoSendSMS1">
<documentation>WSdoSendSMS1</documentation>
<input message="tns:WSdoSendSMS1Request"/>
<output message="tns:WSdoSendSMS1Response"/>
</operation>
<operation name="WSdoSendSMS3">
<documentation>WSdoSendSMS3</documentation>
<input message="tns:WSdoSendSMS3Request"/>
<output message="tns:WSdoSendSMS3Response"/>
</operation>
<operation name="WSdoSendSMS4">
<documentation>WSdoSendSMS4</documentation>
<input message="tns:WSdoSendSMS4Request"/>
<output message="tns:WSdoSendSMS4Response"/>
</operation>
<operation name="WSgetDelivery">
<documentation>WSgetDelivery</documentation>
<input message="tns:WSgetDeliveryRequest"/>
<output message="tns:WSgetDeliveryResponse"/>
</operation>
<operation name="WSchangePassword">
<documentation>WSchangePassword</documentation>
<input message="tns:WSchangePasswordRequest"/>
<output message="tns:WSchangePasswordResponse"/>
</operation>
<operation name="WSgetMessages">
<documentation>WSgetMessages</documentation>
<input message="tns:WSgetMessagesRequest"/>
<output message="tns:WSgetMessagesResponse"/>
</operation>
<operation name="WSgetNewMessages">
<documentation>WSgetNewMessages</documentation>
<input message="tns:WSgetNewMessagesRequest"/>
<output message="tns:WSgetNewMessagesResponse"/>
</operation>
</portType>
<binding name="SMSSYSTEMBinding" type="tns:SMSSYSTEMPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="WSGETBalance">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSGETBalance" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSGETBalance__">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSGETBalance__" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSdoSendSMS1">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSdoSendSMS1" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSdoSendSMS3">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSdoSendSMS3" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSdoSendSMS4">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSdoSendSMS4" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSgetDelivery">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSgetDelivery" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSchangePassword">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSchangePassword" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSgetMessages">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSgetMessages" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="WSgetNewMessages">
<soap:operation soapAction="http://farasms.com/SMSSYSTEM#WSgetNewMessages" style="rpc"/>
<input>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://farasms.com/SMSSYSTEM" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="SMSSYSTEM">
<port name="SMSSYSTEMPort" binding="tns:SMSSYSTEMBinding">
<soap:address location="http://farasms.com/webservice/v2.02.php"/>
</port>
</service>
</definitions>

我做错了什么?

最佳答案

好吧,经过一番查找,终于找到原因了。正确的网址是这样的:

private final String URL = "http://farasms.com/webservice/v2.02.php";

我将 URL 指向 WSDL 本身,而不是 Web 服务!

关于java - Android ksoap2 Web 服务获取 WSDL 的 XML 描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21402346/

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