2009-11-17 28 views
0

我不确定如何在wsdl文件中正确地创建一个错误元素来重传PHP异常。如何在wsdl文件中支持PHP异常

我创建了一个PHP Web服务,它引发一个异常以用于测试目的。当我在一个测试C#项目中调用这个Web服务时,我得到一个反射异常,消息“Item已经被添加了。键入字典:'System.Object'添加的键:'System.Object'”。

所以这显然意味着我没有在wsdl文件中正确创建故障元素。

回答

0

我不了解PHP,或者你在创建错误元素时犯了一个错误。我也不知道你的WSDL或者你的php的样子,但这里有一个可行的故障消息的WSDL的例子:

<?xml version="1.0"?> 
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
        xmlns:tns="http://www.your.site/YourService" 
        targetNamespace="http://www.your.site/YourService" 
        name="ays"> 
    <xsd:import schemaLocation="http://www.your.site/YourService/AtYourService.xsd" 
       namespace="http://www.your.site/YourService"/> 
    <wsdl:message name="Input"> 
     <wsdl:part name="parameters" 
        element="tns:Question"/> 
    </wsdl:message> 

    <wsdl:message name="Output"> 
     <wsdl:part name="info" 
        element="tns:Answer"/> 
    </wsdl:message> 

    <wsdl:message name="Fault"> 
     <wsdl:part name="detail" 
        element="tns:FaultMessage"/> 
    </wsdl:message> 

    <wsdl:portType name="YourPortType"> 
     <wsdl:operation name="Question"> 
      <wsdl:input wsaw:Action="http://www.your.site/YourService/Question" 
         message="tns:Input"/> 
      <wsdl:output wsaw:Action="http://www.your.site/YourService/Answer" 
         message="tns:Output"/> 
      <wsdl:fault wsaw:Action="http://www.your.site/YourService/Fault" 
         name="QuestionFault" 
         message="tns:Fault"/> 
     </wsdl:operation> 
    </wsdl:portType> 

    <wsdl:binding name="YourBinding" 
        type="tns:YourPortType"> 
     <wsdl:operation name="Question"> 
      <soap:operation soapAction="http://www.your.site/YourService/Question" style="document"/> 
      <wsdl:input> 
       <soap:body use="literal"/> 
      </wsdl:input> 
      <wsdl:output> 
       <soap:body use="literal"/> 
      </wsdl:output> 
      <wsdl:fault name="QuestionFault"> 
       <soap:fault name="QuestionFault" use="literal"/> 
      </wsdl:fault> 
     </wsdl:operation> 
    </wsdl:binding> 

    <wsdl:service name="YourService"> 
     <wsdl:port name="YourBinding" binding="tns:YourBinding"> 
      <soap:address location="http://www.your.site/YourService"/> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

问候,米尔。

0

我认为最好是用http状态代码= 200和content-type = text/xml自行返回故障消息。因此,您可以捕捉Flash和Flex中的错误消息。

header("status: 200"); 
    header("Content-Type: text/xml; charset=utf-8"); 
    try { 
     $wsdl = "http://wsdluri"; 
     $serverConfig = array("soap_version"=> SOAP_1_2, "encoding" => "UTF-8"); 
     $server = new SoapServer($wsdl, $serverConfig); 
     $server->setObject($myService); 
     $server->handle($HTTP_RAW_POST_DATA); 
    } catch (Exception $exception) { 
    $xmlstr = 
    <<<XML 
    <?xml version="1.0" encoding="UTF-8"?> 
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Body> 
    <SOAP-ENV:Fault> 
    <faultcode>{$exception->getCode()}</faultcode> 
    <faultstring>{$exception->getMessage()}</faultstring> 
    <detail><![CDATA[{$exception->getTraceAsString()}]]></detail> 
    </SOAP-ENV:Fault> 
    </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope> 
    XML; 
    echo $xmlstr; 
    } 
}