1

I am trying to set up a very simple webservice to consume salesforce outbound messages using php SoapServer class.

The salesforce outbound messages are being successfully received by the notifications method in the code below.

class mySoapHandler {

  public function notifications(){
    $args = func_get_args();
    error_log('notifications args: '.print_r($args,1).' '.__FILE__.' '.__LINE__,0);
    return self::_respond('true');
  }

  private function _respond($tf){
    $ACK = <<<ACK
        <?xml version="1.0" encoding="utf-8"?>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <soapenv:Body>
                <notificationsResponse xmlns="http://soap.sforce.com/2005/09/outbound">
                    <Ack xsi:type="xsd:boolean">$tf</Ack>
                </notificationsResponse>
            </soapenv:Body>
        </soapenv:Envelope>
ACK;
    return $ACK;
  }
}

try {
  $server = new SoapServer(null, array('uri' => 'https://website.com/services/SoapService.php'));
  $server->setClass('mySoapHandler');
  $server->handle();
}
catch(SOAPFault $e) {
  error_log(print_r($e->getMessage(),1).' '.__FILE__.' '.__LINE__,0);
}

What is not working is the respond acknowledgement. It throws this error on the salesforce side: org.xml.sax.SAXException: Bad types (class java.lang.String -> class java.lang.Boolean)

Does anyone know what might be causing this "Bad types" error?

The element schema is at the bottom of this page here: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_om_outboundmessaging_wsdl.htm#i1473596

0

The xml namespace on your notificationsResponse element is wrong it should be http://soap.sforce.com/2005/09/outbound but you have https://website.com/outbound

  • Thanks for the response, but that doesn't seem to have fixed the delivery failure problem. – user1814739 Mar 14 '13 at 18:16
  • well it certainly doesn't have to be the only problem. can you get a capture of what the actual http request/responses look like. – superfell Mar 14 '13 at 18:22
  • is it possible that the SoapServer class is trying to wrap its own soap envelope around the response you provided. – superfell Mar 14 '13 at 18:23
  • I actually don't have access to the salesforce side of things, so I probably won't be able to get that in a hurry, but will try. – user1814739 Mar 14 '13 at 18:26
  • you only need access to the host where your code is running to get a capture of the req/res. You can also just use curl or SoapUI to send a request to your server and see the response. – superfell Mar 14 '13 at 18:27
0

Wanted to post working php code in case it might help somebody:

try {
  $server = new SoapServer(null, array('uri' => 'https://website.com/services/SFService.php'));
  $server->setClass('SoapHandler');
  $server->handle();
}
catch(SOAPFault $e) {
  error_log(print_r($e->getMessage(),1).' '.__FILE__.' '.__LINE__,0);
}

class SoapHandler {
  public function notifications(){
    $args = func_get_args();
    error_log(print_r($args,1).' '.__FILE__.' '.__LINE__,0);
    $response = '<Ack>true</Ack>';
    $response = new SoapVar($response,XSD_ANYXML);
    return $response;
  }
}

superfell was correct that the SoapServer class was wrapping its own soap envelope around the response, which is not very clear in the php manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.