Soap客户端复杂类型PHP请求

时间:2017-11-11 04:38:43

标签: php web-services soap wsdl soap-client

我有一个关注link的网络服务 我尝试使用SubmitRequestType访问函数名称,但似乎该函数不存在submitAnsiSingle这是我到目前为止尝试的正确函数名称,

$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);

但是我收到如下所示的响应似乎请求正在处理,但SecurityHeaderType并未解析它们的结束。

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] => 
        )

)

任何暗示都将非常感激

提前致谢。

2 个答案:

答案 0 :(得分:4)

我找到了解决方案!好像是PHP - &gt; .NET Web服务可比性问题。所以从PHP复杂类型SOAP(这种格式)无法访问我找到了一些有用的帖子here。所以我用CURL将SOAP切换到纯XML请求,看起来工作正常!同样从WSDL链接,我们可以使用此online service提取请求模板。 所以我的最终代码如下所示。

$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);

希望这将有助于其他人。

答案 1 :(得分:1)

您可能正在运行PHP,而不是兼容的WSDL2实现。您可以尝试以下方法并交叉手指;

Headerbody需要以xml中定义的相同深度实现,因为我无法访问navicure的文档,例如代码:

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

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

//如果需要多个标头,请创建$ headers [] = $ header,然后追加到标头。

$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());
}

希望这有任何用处 - 如果实际使用了WSDL2,您可能能够使用nusoap来使用它,这可以在sourceforge上找到。虽然在相当长的一段时间内没有更新......