Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

How to get NAMESPACE, SOAP_ACTION, URL and METHOD_NAME to call SOAP request in android

I have a url for calling in code I should call it with Ksoap2 library in code.

My code is in below,

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);
}

My url is,

https://www.zarinpal.com/pg/services/WebGate/wsdl

I don't know what I should set to namespace, method, action_soap and url in my code.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this,

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;
}

This is how I found NAMESPACE, WSDL, METHOD_NAME and SOAP_ACTION.

  1. NAMESPACE : Search for "targetNamespace" in the WSDL.
  2. WSDL/URL : Search for "soap:address" in the WSDL. The value in location is the URL.
  3. METHOD_NAME : I look at the arguments you were using to create the request. It had Amount, CallbackURL, Description, Email, MerchantID and Mobile (no AdditionalData). So I figured you are trying to call PaymentRequest method.
  4. SOAP_ACTION : Search for "soapAction" in the WSDL. Among the matches, look for the one related to PaymentRequest. The SOAP_ACTION is usually the URL + some_seperator + METHOD_NAME. The separator in this case was #.

And so I found everything that was required to make the request. Hope it helped you. Good luck.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...