Salesforce calls external webservice interface

1. The last part talked about how to generate wsdl from the webservice interface and deploy it to a remote server. The external network can be accessed.

First download the wsdl file, and then import the wsdl into SF. By in Develop->Apex Classes

Then click next, you can get the following picture

Then go to generate the apex code. Two classes are generated. AsyncWeb One is to call the web asynchronously, the other is to call the url synchronously to set the access on the remote site

Note: This url must be accessible from the external network, otherwise the interface will not work.

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://远程主机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://远程主机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 an interface call

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

It can be seen that the call is successful

also output information

 

Now go to the remote server to see some printing information of the call

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324140658&siteId=291194637