function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ram@sfdcRam@sfdc 

How to call php SOAP Web service(External webservice) file from salesforce

Hi,

I have urgent client requirement. Please help me in doing this.
Actually client has send me a php WSDL file which is containing "rpc" style. When I am including this WSDl file in salesforce. I am getting error that "rpc" style doesn't support.

So, How to call wsdl( php SOAP webservice) from salesforce, and in that i have to pass some field values to PHP server.
Please help me in doing this Integration... I tried to do by googling it. But I didn't find out correct solution.

I tried using http callouts as like....

HttpRequest req = new HttpRequest();
req.setEndpoint('http://tfserver.forexwebsolutions.com/tfserver.php?wsdl');
req.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(req);
System.Debug('STATUS:'+response.getStatusCode());
System.Debug('Body:'+response.getBody());

Here I am getting the XML in respose....
Please help me in passing values to php fields... So that it will be very helpful.
sfdcfoxsfdcfox
You're calling the web service's WSDL endpoint, which simply gives you a WSDL file, not API interaction. You would need to write code similar to the following:

<pre>
public class TFServer {
    public class AddUserRecordInfo {
        public integer login1, enable, enable_change_password, enabled_read_only,
            leverage, agent_account;
        public string password, password_investor, password_phone, name,
            address, city, state, country, zipcode, email, comment, group_x,
            phone, status;
    }
    public static String AddUserRecord(AddUserRecordInfo info) {
        Http binding = new Http();
        HttpRequest req = new HttpRequest();
        String responseText = '';
        req.setEndpoint('http://tfserver.forexwebsolutions.com/tfserver.php');
        req.setMethod('POST');
        req.setHeader('SOAPAction','urn:server#AddUserRecord');
        XmlStreamWriter input = new XmlStreamWriter();
        input.writeStartDocument('UTF-8','1.0');
        input.writeStartElement('env', 'envelope', 'http://schemas.xmlsoap.org/soap/envelope/');
        input.writeNamespace('env', 'http://schemas.xmlsoap.org/soap/envelope/');
        input.writeNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
        input.writeNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');
        input.writeNamespace('srv', 'urn:server');
        input.writeStartElement('env', 'body', 'env');
        input.writeStartElement('env', 'AddUserRecord', 'env');
        if(info.login1 != null) {
            input.writeStartElement(null, 'login1', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:int');
            input.writeCharacters(String.valueOf(info.login1));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'login1', null);
        }
        if(info.enable != null) {
            input.writeStartElement(null, 'enable', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:int');
            input.writeCharacters(String.valueOf(info.enable));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'enable', null);
        }
        if(info.enable_change_password != null) {
            input.writeStartElement(null, 'enable_change_password', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:int');
            input.writeCharacters(String.valueOf(info.enable_change_password));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'enable_change_password', null);
        }
        if(info.enabled_read_only != null) {
            input.writeStartElement(null, 'enabled_read_only', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:int');
            input.writeCharacters(String.valueOf(info.enabled_read_only));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'enabled_read_only', null);
        }
        if(info.leverage != null) {
            input.writeStartElement(null, 'leverage', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:int');
            input.writeCharacters(String.valueOf(info.leverage));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'leverage', null);
        }
        if(info.agent_account != null) {
            input.writeStartElement(null, 'agent_account', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:int');
            input.writeCharacters(String.valueOf(info.agent_account));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'agent_account', null);
        }
        if(info.password != null) {
            input.writeStartElement(null, 'password', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.password));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'password', null);
        }
        if(info.password_investor!= null) {
            input.writeStartElement(null, 'password_investor', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.password_investor));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'password_investor', null);
        }
        if(info.password_phone != null) {
            input.writeStartElement(null, 'password_phone', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.password_phone));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'password_phone', null);
        }
        if(info.name!= null) {
            input.writeStartElement(null, 'name', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.name));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'name', null);
        }
        if(info.address!= null) {
            input.writeStartElement(null, 'address', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.address));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'address', null);
        }
        if(info.city!= null) {
            input.writeStartElement(null, 'city', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.city));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'city', null);
        }
        if(info.state!= null) {
            input.writeStartElement(null, 'state', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.state));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'state', null);
        }
        if(info.country!= null) {
            input.writeStartElement(null, 'country', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.country));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'country', null);
        }
        if(info.zipcode!= null) {
            input.writeStartElement(null, 'zipcode', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.zipcode));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'zipcode', null);
        }
        if(info.email!= null) {
            input.writeStartElement(null, 'email', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.email));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'email', null);
        }
        if(info.comment!= null) {
            input.writeStartElement(null, 'comment', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.comment));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'comment', null);
        }
        if(info.group_x!= null) {
            input.writeStartElement(null, 'group', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.group_x));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'group', null);
        }
        if(info.phone!= null) {
            input.writeStartElement(null, 'phone', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.phone));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'phone', null);
        }
        if(info.status!= null) {
            input.writeStartElement(null, 'status', null);
            input.writeAttribute('xsi', 'xsi', 'type', 'xsd:string');
            input.writeCharacters(String.valueOf(info.status));
            input.writeEndElement();
        } else {
            input.writeEmptyElement(null, 'status', null);
        }
        input.writeEndDocument();
        req.setBody(input.getXmlString());
        HttpResponse res = binding.send(req);
        XmlStreamReader reader = res.getXmlStreamReader();
        while(reader.hasNext()) {
            if(reader.getEventType() == XMLTAG.CHARACTERS) {
                responseText += reader.getText();
            }
            reader.next();
        }
        return responseText;
    }
}
</pre>