2014-09-07 1 views
1

Sonos' Music API (SMAPI)에 대한 서비스를 구축 중입니다.PHP의 SOAP 라이브러리를 사용하여 SoapFault의 세부 구역에 사용자 지정 요소를 추가하는 방법

throw new SoapFault('Client.NOT_LINKED_RETRY', 'Link Code not found retry...'); 

그러나 때 나는 PHP SOAP library하고, 상기 응답 나는이 같은 SoapFault을 던지는 시도를 사용하여 내 서비스를 구축하고

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <soap:Fault> 
     <faultcode>Client.NOT_LINKED_RETRY</faultcode> 
     <faultstring>Link Code not found retry...</faultstring> 
     <detail> 
      <ExceptionInfo>NOT_LINKED_RETRY</ExceptionInfo> 
      <SonosError>5</SonosError> 
     </detail> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

: 가끔 다음과 같은 형식의 응답을 다시 전송해야 더 ExceptionInfo 그이 없음을

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <soap:Fault> 
     <faultcode>Client.NOT_LINKED_RETRY</faultcode> 
     <faultstring>Link Code not found retry...</faultstring> 
     <detail> 
      <SonosError/> 
     </detail> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

주의 사항 :이처럼 다시 전송 보인다되는이 응답을 시도이 비어 있습니다. ExceptionInfoSonosErrorSoapFault을 사용하여 설정할 수 있습니까? 나는 모든 종류의 것들을했지만, 내가 지금이 일을하고 주위에 그렇게 작품으로, 작업을 가져올 수 없습니다 : 그것은 관련이 있지만, WSDL은 here을 찾을 수 있습니다

http_response_code(500); 
header("Content-type: text/xml"); 

$ret = '<?xml version="1.0" encoding="UTF-8"?>'."\n"; 
$ret .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">'; 
$ret .= '<SOAP-ENV:Body>'; 
$ret .= '<SOAP-ENV:Fault>'; 
$ret .= '<faultcode>Client.NOT_LINKED_RETRY</faultcode>'; 
$ret .= '<faultstring>Link Code not found retry...</faultstring>'; 
$ret .= '<detail>'; 
$ret .= '<ExceptionInfo>NOT_LINKED_RETRY</ExceptionInfo>'; 
$ret .= '<SonosError>5</SonosError>'; 
$ret .= '</detail>'; 
$ret .= '</SOAP-ENV:Fault>'; 
$ret .= '</SOAP-ENV:Body>'; 
$ret .= '</SOAP-ENV:Envelope>'."\n"; 

echo $ret; exit; 

확실하지합니다. 나는이 같은 아래의 제안하려고 할 때 :

업데이트

$detail = new StdClass(); 
$detail->SonosError = 5; 
$detail->ExceptionInfo = 'NOT_LINKED_RETRY'; 

throw new SoapFault(
    'Client.NOT_LINKED_RETRY', 
    'Link Code not found retry...', 
    NULL, 
    $detail 
); 

를 내가 얻을 :

<detail> 
    <customFault> 
    <SonosError>5</SonosError> 
    <ExceptionInfo>NOT_LINKED_RETRY</ExceptionInfo> 
    </customFault> 
</detail> 

이 내가 <customFault> 태그를 제외하고, 필요가 거의 것입니다. 그것을 없애는 방법이 SonosErrorExceptionInfo<detail>에 직접 있습니까?

+0

처럼된다? – alkis

답변

2

ExceptionInfo 태그가 표시되지 않는 이유는 wsdl에 태그가 정의되어 있지 않기 때문입니다. 반면에 SonosError이 정의됩니다. 먼저 SonosError을 채우려면 인수를 전달해야합니다. here에서

이 생성자는 SonosErrorExceptionInfo에 관해서는이

$detail = new StdClass(); 
$detail->SonosError = 5; 
throw new SoapFault('Client.NOT_LINKED_RETRY', 'Link Code not found retry...', null, $details); 

처럼 전화를 통과하기 위해 더 많은 매개 변수

SoapFault('code', 'string', 'actor', 'detail', 'name', 'header'); 

을 가지고 있음을 볼 수 있으며, WSDL을 변경해야합니다. 그것은 지금으로, details 태그는 당신이와 위의 섹션을 변경하는 경우

<wsdl:message name="customFault"> 
    <wsdl:part name="customFault" element="tns:SonosError"/> 
</wsdl:message> 

<xs:element name="SonosError" type="xs:int"/> 

, 당신은 당신이 필요 것이 섹션으로 표시됩니다.

<wsdl:message name="customFault"> 
    <wsdl:part name="customFault" type="tns:customFaultType" /> 
</wsdl:message> 

<xs:complexType name="customFaultType"> 
    <xs:sequence> 
     <xs:element name="SonosError" type="xs:int"/> 
     <xs:element name="ExceptionInfo" type="xs:string"/> 
    </xs:sequence> 
</xs:complexType> 

그리고 물론

당신은 매개 변수를 추가하고 배열은 WSDL을 변경할 수이

$detail = new StdClass(); 
$detail->SonosError = 5; 
$detail->ExceptionInfo = 'NOT_LINKED_RETRY'; 
+0

답변 해 주셔서 감사합니다! 나는 그 모든 다른 주장을 시도했으나 제대로 작동하지 못했습니다. '$ details'를 배열로 전달하려고 생각했지만, 문서에'string $ detail'이라고 쓰여 있으므로 배열을 받아들이지 않을 것이라고 생각했습니다. 나는 당신에게 제안을 시도 할 것이다. – Mischa

+0

배열 대신 객체를 사용하면 거의 필요한 부분을 얻을 수 있습니다. 유일한 문제는'SonosError'와'ExceptionInfo'가''안에 있다는 것입니다. ''안에 직접 들어가는 방법이 있습니까? 즉, 어떻게하면 ''을 제거 할 수 있습니까? – Mischa

+1

결국에는'ExceptionInfo'가 필요 없기 때문에 다음과 같이했습니다 :'$ detail = new StdClass(); $ detail-> SonosError = 5; 새로운 SoapFault를 던지십시오 ('Client.NOT_LINKED_RETRY', '아직 연결되지 않았습니다. 다시 시도하십시오.', NULL, $ detail); – Mischa

관련 문제