2014-03-03 5 views
0

WSDL 모드에서 PHP SoapClient를 사용하고 있습니다. PHP SoapClient 대상 네임 스페이스가 요청 매개 변수에 없음

가 예상되는 SOAP 요청이 어떻게 보일지입니다 :

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns="http://xml.m4u.com.au/2009"> 
<soapenv:Header/> 
<soapenv:Body> 
<ns:sendMessages> 
    <ns:authentication> 
    <ns:userId>Username</ns:userId> 
    <ns:password>Password</ns:password> 
    </ns:authentication> 
    <ns:requestBody> 
    <ns:messages> 
     <ns:message> 
     <ns:recipients> 
      <ns:recipient>61400000001</ns:recipient> 
     </ns:recipients> 
     <ns:content>Message Content</ns:content> 
     </ns:message> 
    </ns:messages> 
    </ns:requestBody> 
</ns:sendMessages> 
</soapenv:Body> 
</soapenv:Envelope> 

그리고 이것은 PHP SoapClient가 보내는 것입니다 :

:

<SOAP-ENV:Envelope 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="http://xml.m4u.com.au/2009"> 
<SOAP-ENV:Header/> 
<SOAP-ENV:Body> 
<ns1:sendMessages> 
    <ns1:authentication> 
    <userId>Username</userId> 
    <password>Password</password> 
    </ns1:authentication> 
    <ns1:requestBody> 
    <messages> 
     <message> 
     <recipients> 
      <recipient>61400000001</recipient> 
     </recipients> 
     <content>Message Content</content> 
     </message> 
    </messages> 
    </ns1:requestBody> 
</ns1:sendMessages> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

이 내가 클라이언트와 PARAMS을 구성하는 방법입니다

function sendMessages($recipient, $content) { 

    $authenticationType = new SoapVar(array('userId' => $this->username, 'password' => $this->password), SOAP_ENC_OBJECT); 

    $recipientsType = new SoapVar(array('recipient' => $recipient), SOAP_ENC_OBJECT); 
    $messageType = new SoapVar(array('recipients' => $recipientsType, 'content' => $content), SOAP_ENC_OBJECT); 
    $messagesType = new SoapVar(array('message' => $messageType), SOAP_ENC_OBJECT); 

    $requestBodyType = new SoapVar(array('messages' => $messagesType), SOAP_ENC_OBJECT); 

    $params = array(
       'authentication' => $authenticationType, 
       'requestBody' => $requestBodyType 
      ); 

    try { 
     $this->soapClient = new SoapClient($this->wsdl, array('trace' => 1)); 
     $this->soapClient->__setSoapHeaders(array()); 

     return $this->soapClient->sendMessages($params); 

    } catch (SoapFault $fault) { 
     echo '<h2>Request</h2><pre>' . htmlspecialchars($this->soapClient->__getLastRequest(), ENT_QUOTES) . '</pre>'; 
     trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR); 
    } 

} 

'인증'및 'requestBody'에 'ns1'이 ir 자식 노드? 내가 뭘 잘못하고 있니? WSDL은 여기에 있습니다.>>http://soap.m4u.com.au/?wsdl

도움을 줄 수있는 모든 사람을 알아보십시오.

답변

0

개체를 인코딩하려면 네임 스페이스의 URI를 지정해야합니다. 여기에는 필요한 네임 스페이스를 포함하여 필요한 모든 것이 포함됩니다. 네임 스페이스 이름의 약어는 부적합합니다.

이 :

$authenticationType = new SoapVar(array('userId' => $this->username, 'password' => $this->password), SOAP_ENC_OBJECT); 

가 있어야한다 :

네임 스페이스 직렬화로보고있는 문제는 모든 매개 변수없이 soapvar를 사용에서 오는
$authenticationType = new SoapVar(array('userId' => $this->username, 'password' => $this->password), SOAP_ENC_OBJECT, "authentication","http://xml.m4u.com.au/2009"); 

. 전송 전에 요청을 직렬화하면 네임 스페이스가 이고 이미이 포함되어 있다고 가정합니다. 대신 각각을 간단한 배열로 만들고이를 $params에 포함 시키면 내부 매개 변수의 네임 스페이스가 올바르게 포함됩니다. 데모 방법 :

$authenticationType = array('userId' => $this->username, 'password' => $this->password) 
0

nusoap 라이브러리를 사용해보세요. 다음은 샘플 코드입니다.

<?php 
$wsdl = "http://soap.m4u.com.au/?wsdl"; 
// generate request veriables 
$data = array(); 

$action = ""; // ws action 
$param = ""; //parameters 

$options = array(
      'location' => 'http://soap.m4u.com.au', 
      'uri'  => '' 
      ); 
// eof generate request veriables 

//$client = new soap_client($wsdl, $options);// create soap client 
$client = new nusoap_client($wsdl, 'wsdl'); 

$client->setCredentials($api_username, $api_password);// set crendencials 
$opt = $client->call($action, $param, '', '', false, true); 

print_r($opt); 
?> 
관련 문제