如何获取 NAMESPACE、SOAP_ACTION、URL 和 METHOD_NAME 以在 android 中调用 SOAP 请求
How to get NAMESPACE, SOAP_ACTION, URL and METHOD_NAME to call SOAP request in android
我有一个 url 用于在代码中调用我应该在代码中使用 Ksoap2 库调用它。
我的代码在下面,
final String NAMESPACE ="";
final String URL ="";
final String METHOD_NAME = "";
final String SOAP_ACTION = "";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty(HoldPayment.Amount, "1000");
request.addProperty(HoldPayment.CallbackURL,"http://www.yoursoteaddress.ir/verify.php");
request.addProperty(HoldPayment.Description,"pule kharide tala");
request.addProperty(HoldPayment.Email,"za@gmail.com");
request.addProperty(HoldPayment.MerchantID,"e579752a-a591-11e6-9304-000c295eb8fc");
request.addProperty(HoldPayment.Mobile,"09012345678");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION,envelope);
Object resultsRequestSOAP = envelope.bodyIn;
Log.e("","Response::"+resultsRequestSOAP.toString());
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error"+e);
}
我的url是,
https://www.zarinpal.com/pg/services/WebGate/wsdl
我不知道我应该在我的代码中为命名空间、方法、action_soap 和 url 设置什么。
试试这个,
private static final String NAMESPACE ="http://zarinpal.com/";
private static final String WSDL ="https://www.zarinpal.com/pg/services/WebGate/service";
private static final String METHOD_NAME = "PaymentRequest";
private static final String SOAP_ACTION = WSDL + "#" + METHOD_NAME;
private static String TAG = "soap";
public static String callWebservice() {
String responseDump = "";
try {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty(HoldPayment.Amount, "1000");
request.addProperty(HoldPayment.CallbackURL,"http://www.yoursoteaddress.ir/verify.php");
request.addProperty(HoldPayment.Description,"pule kharide tala");
request.addProperty(HoldPayment.Email,"za@gmail.com");
request.addProperty(HoldPayment.MerchantID,"e579752a-a591-11e6-9304-000c295eb8fc");
request.addProperty(HoldPayment.Mobile,"090123456789");
envelope.bodyOut = request;
HttpTransportSE transport = new HttpTransportSE(WSDL);
transport.debug = true;
try {
transport.call(SOAP_ACTION, envelope);
String requestDump = transport.requestDump;
responseDump = transport.responseDump;
Log.e(TAG, requestDump);
Log.e(TAG, responseDump);
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return responseDump;
}
这就是我找到 NAMESPACE
、WSDL
、METHOD_NAME
和 SOAP_ACTION
的方式。
- 名称空间:在 WSDL 中搜索 "targetNamespace"。
- WSDL/URL :在 WSDL 中搜索 "soap:address"。 location 中的值是 URL.
- METHOD_NAME :我查看了您用来创建请求的参数。它有金额、回调URL、描述、电子邮件、MerchantID 和手机(无附加数据)。所以我认为您正在尝试调用
PaymentRequest
方法。
- SOAP_ACTION :在 WSDL 中搜索 "soapAction"。在匹配项中,查找与
PaymentRequest
相关的匹配项。 SOAP_ACTION 通常是 URL + some_seperator + METHOD_NAME。本例中的分隔符是 #
.
所以我找到了提出请求所需的一切。希望对您有所帮助。祝你好运。
我有一个 url 用于在代码中调用我应该在代码中使用 Ksoap2 库调用它。
我的代码在下面,
final String NAMESPACE ="";
final String URL ="";
final String METHOD_NAME = "";
final String SOAP_ACTION = "";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty(HoldPayment.Amount, "1000");
request.addProperty(HoldPayment.CallbackURL,"http://www.yoursoteaddress.ir/verify.php");
request.addProperty(HoldPayment.Description,"pule kharide tala");
request.addProperty(HoldPayment.Email,"za@gmail.com");
request.addProperty(HoldPayment.MerchantID,"e579752a-a591-11e6-9304-000c295eb8fc");
request.addProperty(HoldPayment.Mobile,"09012345678");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION,envelope);
Object resultsRequestSOAP = envelope.bodyIn;
Log.e("","Response::"+resultsRequestSOAP.toString());
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error"+e);
}
我的url是,
https://www.zarinpal.com/pg/services/WebGate/wsdl
我不知道我应该在我的代码中为命名空间、方法、action_soap 和 url 设置什么。
试试这个,
private static final String NAMESPACE ="http://zarinpal.com/";
private static final String WSDL ="https://www.zarinpal.com/pg/services/WebGate/service";
private static final String METHOD_NAME = "PaymentRequest";
private static final String SOAP_ACTION = WSDL + "#" + METHOD_NAME;
private static String TAG = "soap";
public static String callWebservice() {
String responseDump = "";
try {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty(HoldPayment.Amount, "1000");
request.addProperty(HoldPayment.CallbackURL,"http://www.yoursoteaddress.ir/verify.php");
request.addProperty(HoldPayment.Description,"pule kharide tala");
request.addProperty(HoldPayment.Email,"za@gmail.com");
request.addProperty(HoldPayment.MerchantID,"e579752a-a591-11e6-9304-000c295eb8fc");
request.addProperty(HoldPayment.Mobile,"090123456789");
envelope.bodyOut = request;
HttpTransportSE transport = new HttpTransportSE(WSDL);
transport.debug = true;
try {
transport.call(SOAP_ACTION, envelope);
String requestDump = transport.requestDump;
responseDump = transport.responseDump;
Log.e(TAG, requestDump);
Log.e(TAG, responseDump);
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return responseDump;
}
这就是我找到 NAMESPACE
、WSDL
、METHOD_NAME
和 SOAP_ACTION
的方式。
- 名称空间:在 WSDL 中搜索 "targetNamespace"。
- WSDL/URL :在 WSDL 中搜索 "soap:address"。 location 中的值是 URL.
- METHOD_NAME :我查看了您用来创建请求的参数。它有金额、回调URL、描述、电子邮件、MerchantID 和手机(无附加数据)。所以我认为您正在尝试调用
PaymentRequest
方法。 - SOAP_ACTION :在 WSDL 中搜索 "soapAction"。在匹配项中,查找与
PaymentRequest
相关的匹配项。 SOAP_ACTION 通常是 URL + some_seperator + METHOD_NAME。本例中的分隔符是#
.
所以我找到了提出请求所需的一切。希望对您有所帮助。祝你好运。