Salesforce calls the external webservice interface

1, The previous article described how to generate wsdl from web service interface and deploy it to remote server. The Internet can be accessed.

First download the wsdl file, and then import the wsdl into SF. Through developing - > apex classes

Then click next to get the following figure

Then generate the code of apex. Two classes are generated. AsyncWeb is an asynchronous call to the web and a synchronous call to the url to be accessed at the remote site

Note: this url should be accessible on the Internet, otherwise the interface cannot be called

public class AsyncWeb {
    public class sendOAResponseFuture extends System.WebServiceCalloutFuture {
        public Boolean getValue() {
            web.sendOAResponse response = (web.sendOAResponse)System.WebServiceCallout.endInvoke(this);
            return response.return_x;
        }
    }
    public class AsyncSendServiceImplPort {
        public String endpoint_x = 'http://Remote host IP:8080/CXFWebservice/webservice/sendServie ';
        public Map<String,String> inputHttpHeaders_x;
        public String clientCertName_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://siyuan.com/', 'web'};
        public AsyncWeb.sendOAResponseFuture beginSendOA(System.Continuation continuation,String param) {
            web.sendOA request_x = new web.sendOA();
            request_x.param = param;
            return (AsyncWeb.sendOAResponseFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncWeb.sendOAResponseFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://siyuan.com/',
              'sendOA',
              'http://siyuan.com/',
              'sendOAResponse',
              'web.sendOAResponse'}
            );
        }
    }
}
public class web {
    public class sendOAResponse {
        public Boolean return_x;
        private String[] return_x_type_info = new String[]{'return','http://siyuan.com/',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://siyuan.com/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class sendOA {
        public String param;
        private String[] param_type_info = new String[]{'param','http://siyuan.com/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://siyuan.com/','false','false'};
        private String[] field_order_type_info = new String[]{'param'};
    }
    public class SendServiceImplPort {
        public String endpoint_x = 'http://Remote host IP:8080/CXFWebservice/webservice/sendServie ';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://siyuan.com/', 'web'};
        public Boolean sendOA(String param) {
            web.sendOA request_x = new web.sendOA();
            request_x.param = param;
            web.sendOAResponse response_x;
            Map<String, web.sendOAResponse> response_map_x = new Map<String, web.sendOAResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://siyuan.com/',
              'sendOA',
              'http://siyuan.com/',
              'sendOAResponse',
              'web.sendOAResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
    }
}

Then in the anonymous class, make the interface call

web.SendServiceImplPort us = new web.SendServiceImplPort();
us.sendOA('hello ss');
System.debug('mess'+us.sendOA('hello ss'));

You can see that the call is successful

It also outputs information

 

Now go to the remote server to see some printing information called

Posted on Wed, 03 Jun 2020 07:30:14 -0700 by WinterDragon