2016-10-17 4 views
1

"ns1"을 "ret"로 변경하고 "ret"로 설정된 네임 스페이스로 SoapUI를 사용하여 아래 XML을 테스트 한 결과 요청이 성공했습니다. 나는 "googled"하고, 여기에서 다른 관련 질문들로부터 답을 찾았지만 운이 없다. 그래서, 여기 PHP SoapClient 요청에서 네임 스페이스를 변경하고 있습니까?

요청에 전송 될 생성되는 XML입니다 ... 답을 찾을 수 종류의 필사적 :

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://retailexpress.com.au/"> 
    <SOAP-ENV:Header> 
     <ns1:ClientHeader> 
      <ns1:ClientID>Random-hash-clientID</ns1:ClientID> 
      <ns1:UserName>Username</ns1:UserName> 
      <ns1:Password>Password</ns1:Password> 
     </ns1:ClientHeader> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <ns1:CustomerGetBulkDetails> 
      <ns1:LastUpdated>2000-01-01T00:00:00.000Z</ns1:LastUpdated> 
      <ns1:OnlyCustomersWithEmails>1</ns1:OnlyCustomersWithEmails> 
     </ns1:CustomerGetBulkDetails> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

비록, 우리가 요청해야하는 것이 조금 이상한 것 같다

$rexHost = '<domain of retail express>'; 
    $rexApi = '<URI of retail express API/wsdl path>'; 
    $rexUser = 'Username'; 
    $rexPassword = 'Password'; 
    $rexApiClient = 'Random-hash-clientID'; 
    $rexApiHost = 'http://retailexpress.com.au/'; 

    $client = new SoapClient($rexHost.$rexApi, array('trace' => true)); 

    $auth = new stdClass(); 
    $auth->ClientID = $rexApiClient; 
    $auth->UserName = $rexUser; 
    $auth->Password = $rexPassword; 

    $header = new SoapHeader($rexApiHost, 'ClientHeader', $auth, false); 
    $client->__setSoapHeaders($header); 

    $lastUpdate = '2000-01-01T00:00:00.000Z'; //hardcoded for test 

    $params = array(); 
    $params[] = new SoapVar($lastUpdate, XSD_DATETIME, null, null, 'LastUpdated', $rexApiHost); 
    $params[] = new SoapVar(1, XSD_INTEGER, null, null, 'OnlyCustomersWithEmails', $rexApiHost); 

    try { 
     $users = null; 
     return $users = $client->CustomerGetBulkDetails(new SoapVar($params, SOAP_ENC_OBJECT)); 
    } catch (Exception $e) { 
     Log::info($e->getMessage()); 
     Log::info($client->__getLastRequest()); //laravel logger, where I got the generated SOAP XML request 
     return false; 
    } 
+0

코드에 문제가 없습니다. 문제를 찾을 수 있었습니까? –

+1

네임 스페이스를 변경하는 방법을 찾지 못했습니다. 하지만 이제는 단일 코드를 변경하지 않고도 작동하는 것 같습니다. 아마도 우리가 지원을 요청했기 때문에 문제를 해결할 수 있었을 것입니다. 네임 스페이스 "ns1"은 SOAP 요청과 함께 API로 작동합니다 ... 감사합니다! – jediscript

+0

아 서버 문제 :) –

답변

1

ns1 네임 스페이스하지만 별칭되지 않습니다 : 같은 네임 스페이스 (RET)와 함께,하지만 여기에

위를 생성하는 데 사용되는 PHP 코드입니다 ... 그것이 방법 그것을 위해. http://retailexpress.com.au/은 네임 스페이스입니다. 네임 스페이스 정의 xmlns:ns1="http://retailexpress.com.au/"은 현재 요소와 그 자손에 대한 별칭을 정의합니다. 네임 스페이스는 고유하고 안정적이어야합니다. 정의와 별칭을 사용하면 복잡한 URI를 네임 스페이스로 사용하고 직렬화에 대한 짧은 읽을 수있는 별칭을 사용할 수 있습니다. 즉

  • <ns1:CustomerGetBulkDetails xmlns:ns1="http://retailexpress.com.au/"/>
  • <ret:CustomerGetBulkDetails xmlns:ret="http://retailexpress.com.au/"/>
  • <CustomerGetBulkDetails xmlns="http://retailexpress.com.au/"/>

, 경우 :

다음 세 가지 예

모든 XML 파서에 의해 네임 스페이스 http://retailexpress.com.au/에 요소 CustomerGetBulkDetails 및 해결 XML/SOAP 구현이 올바르게 작동하는지 여부는 별칭 - ns1 또는 ret -이 네임 스페이스로 사용됩니다.

+0

별칭이 전체 XML에서 일관성이있는 한? – jediscript

+0

하위 요소 노드에서 재정의 될 때까지는 현재 요소와 모든 특성/하위 노드에 유효합니다. 그래서 네, 하나의 네임 스페이스에 대해 여러 개의 별칭을 갖거나 하나의 XML 문서에서 여러 네임 스페이스에 대해 동일한 별칭을 가질 수 있습니다. 물론 그것을 피하려고 노력해야합니다. XML을 사용하면 사람이 읽을 수 없게됩니다. 그러나 예를 들어 다른 문서의 단편을 기존 문서로 복사 할 수 있습니다. – ThW

관련 문제