6

I have a web-service with following link I'm trying to access the function name with SubmitRequestType but it seems the function is not exist instead submitAnsiSingle this is the correct function name what I tried so far is ,

$wsdl = 'https://ww3.navicure.com:7000/webservices/NavicureSubmissionService?WSDL';

class SecurityHeaderType {
        private $submitterIdentifier;
        private $originatingIdentifier;
        private $submitterPassword;
        private $submissionId;
        function SecurityHeaderType() {
            $this->submitterIdentifier = '***';
            $this->originatingIdentifier = '****';
            $this->submitterPassword = '****';
            $this->submissionId = '';

        }           
}

class SubmitRequestType {

        private $submitterIdentifier;
        private $originatingIdentifier;
        private $submitterPassword;
        private $submissionId;
        private $timeout;
        private $transactionType;
        private $submittedAnsiVersion;
        private $resultAnsiVersion;
        private $submitterSubmissionId;
        private $processingOption;
        private $payload;
        private $exceptions;

        function SubmitRequestType() {

        $this->submitterIdentifier = '***';
        $this->originatingIdentifier = '***';
        $this->submitterPassword = '**';
        $this->submissionId = '**';
        $this->timeout = 60 ;
        $this->transactionType = "E";
        $this->submittedAnsiVersion = '5010';
        $this->resultAnsiVersion = '5010';
        $this->submitterSubmissionId = '**';
        $this->processingOption = 'R';
        $this->payload = 'EDI-270-Request';
        $this->exceptions = true;
        }
}

$soapheader = new SecurityHeaderType();


$submitrequest = new SubmitRequestType();



    $service = new \SoapClient($wsdl);
    $result= $service->SubmitAnsiSingle($submitrequest);
    echo "<pre/>";print_r($result);

    $types = $service->__getTypes ();
    $functions = $service->__getFunctions ();
    //echo "<pre/>";print_r($types);
    //echo "<pre/>";print_r($functions);

But I'm getting the response like below it seems the request is processing on their end but the SecurityHeaderType is not parsing their end.

stdClass Object
(
    [transactionTyp] => E
    [submitterSubmissionId] => ****
    [submittedAnsiVersion] => 5010
    [resultAnsiVersion] => 5010
    [statusHeader] => stdClass Object
        (
            [statusCode] => 1150
            [statusMessage] => com.navicure.webservices.core.WSCoreException: Account does not exist for ''
            [requestProcessed] => 
        )

)

Any hint will be highly appreciate

Thanks in advance.

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • I see you create `$soapheader` but not use it – Scuzzy Nov 11 '17 at 04:43
  • @Scuzzy Yes, but that params already I added in `$submitrequest` too bcoz I didn't find a way to call security header along with request. when I print the functions `submitAnsiSingle(SubmitRequestType $parameters)` – Jobin Nov 11 '17 at 04:47
  • `$client->__setSoapHeaders($header);` http://php.net/manual/en/class.soapheader.php – Scuzzy Nov 11 '17 at 04:50
  • tried that too not sure this is the way, `$header = new \SoapHeader('NAMESPACE','Auth',$soapheader,false); $service->__setSoapHeaders($header);` also NAMESPACE thing – Jobin Nov 11 '17 at 04:58
  • tried this too no luck, `$header = new \SoapHeader('http://www.navicure.com/2009/11/NavicureSubmissionService','SecurityHeaderType',$soapheader,false);` – Jobin Nov 11 '17 at 05:06

2 Answers2

4

I found the solution!. It seems the PHP -> .NET web service comparability issue. So from PHP the complex type SOAP (this kind of format) can't access I found some usefull post here. So I switched SOAP to plain XML request with CURL and it seems working fine!. Also from WSDL link we can extract the request template using this online service . So my final code look like below.

$xml_data = "<?xml version='1.0' encoding='UTF-8'?>
<s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>
  <s12:Header>
    <ns1:SecurityHeaderElement xmlns:ns1='http://www.navicure.com/2009/11/NavicureSubmissionService'>
      <ns1:originatingIdentifier>****</ns1:originatingIdentifier>
      <ns1:submitterIdentifier>****</ns1:submitterIdentifier>
      <ns1:submitterPassword>***</ns1:submitterPassword>
      <ns1:submissionId>?999?</ns1:submissionId>
    </ns1:SecurityHeaderElement>
  </s12:Header>
  <s12:Body>
    <ns1:SubmitAnsiSingleRequestElement xmlns:ns1='http://www.navicure.com/2009/11/NavicureSubmissionService'>
      <ns1:timeout>60</ns1:timeout>
      <ns1:transactionType>E</ns1:transactionType>
      <ns1:submittedAnsiVersion>5010</ns1:submittedAnsiVersion>
      <ns1:resultAnsiVersion>5010</ns1:resultAnsiVersion>
      <ns1:submitterSubmissionId></ns1:submitterSubmissionId>
      <ns1:processingOption>R</ns1:processingOption>
      <ns1:payload>EDI270Payload</ns1:payload>
    </ns1:SubmitAnsiSingleRequestElement>
  </s12:Body>
</s12:Envelope>";
$URL = "https://ww3.navicure.com:7000/webservices/NavicureSubmissionService";

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch); 

print_r($output);

Hope this will help someone else in future.

Jobin
  • 8,238
  • 1
  • 33
  • 52
1

You might be running into PHP's slightly less than compatible WSDL2 implementation. You could try the following and cross your fingers;

Headerbody needs to be implemented in the same depth as defined in xml, since I do not have access to navicure's documentation here's example code:

$headerbody = array('Token' => $someToken, 
                    'Version' => $someVersion, 
                    'UserCredentials'=>array('UserID'=>$UserID, 
                                             'Password'=>$Pwd)); 

//Create Soap Header.        
$header = new SOAPHeader($namespace, 'RequestorCredentials', $headerbody);  

// In case multiple headers are required, create $headers[] = $header, and append to headers after.

$options = array(
        'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
        'style'=>SOAP_RPC,
        'use'=>SOAP_ENCODED,
        'soap_version'=>SOAP_1_1,
        'cache_wsdl'=>WSDL_CACHE_NONE,
        'connection_timeout'=>15,
        'trace'=>true,
        'encoding'=>'UTF-8',
        'exceptions'=>true,
    );
try {
    $soap = new SoapClient($wsdl, $options);
    $soap->__setSoapHeaders($header);
    $data = $soap->SubmitAnsiSingle(array($submitrequest));
}
catch(Exception $e) {
    die($e->getMessage());
}

Hope this is of any use - in case WSDL2 is actually used you might be able to get it to work with nusoap which can be found on sourceforge. Although that hasn't been updated in quite a while..

DevionNL
  • 142
  • 1
  • 12
  • Thanks for the answer , I tried something like this before `$header = new \SoapHeader($namespace ,'SecurityHeaderType' ,$soapheader ,false); $service->__setSoapHeaders($header);` but still no luck, and figure out the crazy fact is its working fine from .NET, even the SubmitAnsiSingle() method has two object argument showing in .NET, header and request type. Also searched in deep found some .NET SOAP can't simply access from PHP so might need an XML call. – Jobin Nov 14 '17 at 03:54
  • nusoap I checked, It has some version compatability issue as well, I'm using PHP7.0 so I think https://stackoverflow.com/questions/471115/how-to-post-soap-request-from-php Ivan Krechetov point make sense and plan to use CURL instead of his method. – Jobin Nov 14 '17 at 03:59
  • Yeh as mentioned, PHP has some issues with WSDL based API's and since REST is getting more popular I doubt PHP will ever fix them. If you keep running into problems a slightly crappy solution would be to create a REST API in C# that relays your PHP Requests to the WSDL service. It solves a lot of headaches :) – DevionNL Nov 14 '17 at 09:48