English 中文(简体)
How do you support PHP exceptions in a wsdl file
原标题:

I am not sure how to correctly make a fault element in a wsdl file repesenting a PHP exception.

I have created a PHP web service that throws an exception for testing purposes. When I call this web service in a test C# project, I get a reflection exception with the message "Item has already been added. Key in dictionary: System.Object Key being added: System.Object ".

So this obviously means I have not created the fault element correctly in the wsdl file.

问题回答

I don t know about PHP, or how obvious it is that you made a mistake in the creation of your fault element. Nor do I know what your wsdl or your php looks like, but here s an example of a wsdl with a fault message that works:

<?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>

Regards, Miel.

I think it s better to return oneself the fault message with http status code = 200 and content-type = text/xml. Thus, you can catch fault message within Flash and 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;
    }
}




相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签