Hey!

I'm having problems connecting / calling a SOAP server.

Background:

I have a generated XML-file to be sent to a SOAP-server. The XML-file is generated to a variable. (Templated using sprintf from an UTF-8 encoded file)

I connect to the SOAP server using a WDSL file, no exception is caught here.

I then try to use __SoapCall.

Errors:

I get errors using two different scenarios:

1. Sending the xml file-variable as is

I get the following error:
SOAP-ERROR: Encoding: string <my xml file here.. atleast the first 30%>

1. Sending the xml file-variable as encoded UTF-8

The server (my local test server) disconnects me, and no output is given)
(I've tried both mb string and utf8_encode

Extra info:

This is the soapCall code:

 		$response = parent::__soapCall("AnsoegningGem", $request = array(
 															'Brugernavn' => "Myrealusername",
   			  											    'Password' => "Myrealpassword",
   														    'AnsoegningInd' => $xmlfile));

'This is an excerpt from the WSDL-file:

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="AnsoegningGem">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Brugernavn" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="AnsoegningInd" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>

Why isn't this working? If you need additional info, I'll provide it.

    One funny problem I've had with SOAP/WSDL is that you depend on it to automatically create an object for you and PHP, depending on how it's configured, can fail without any output if you try to call a nonexistent method on an object. For starters, I would try to set up your PHP script to turn up the error reporting:

    error_reporting(E_ALL);
    if (!ini_get('display_errors')) {
        ini_set('display_errors', 1);
    }
    

    The other tricky part here is making sure that your outgoing XML is properly encoded as UTF-8. That involves a lot of steps.

    It sounds to me like you are trying to create your outgoing xml code and put it in $xmlfile by
    1) loading some XML from a file
    2) inserting some data into that xml by using sprintf

    Some things to consider:
    Your original XML file might not be saved as UTF-8. If it's saved is ISO-8859-1 or Latin 1 or some other character encoding, then it is NOT utf-8. I would recommend that you try to make sure that you saved the file as utf-8. On windows, you can do this by pasting the XML into notepad and making sure it looks correct and then when you do a 'save as...', make sure you select utf-8 encoding on the save dialog -- the encoding select is right next to the save button.
    Make sure your XML doesn't use curly quotes or other weird characters that are not proper xml. Check it closely.
    I'm not sure how you are reading the XML file in, but I'm guessing that you are using file_get_contents or something like that. As I understand things, this should result in the file's contents being read verbatim byte-for-byte. This may include a byte marker in the file that windows uses to tell the OS that the file is utf-8.
    I don't think [man]sprintf[/man] is necessarily utf-8 friendly. Read the documentation page's comments. They are full of suggestions about how to deal with utf-8 situations when using sprintf -- including defining new functions to handle the issue.
    I don't know what kind of data you are merging into your xml using sprintf, but you will need to make sure that this data is encoded as utf-8. Unfortunately, that's not as simple as just calling [man]utf8_encode[/man] on it. You need to take into account the source and what encoding that is
    - if it's an html form, check the encoding of the page that hosts it for a charset declaration
    - if it's a database, check the character encoding used for the connection, the table, and the particular fields you are using
    - if it's from a file, check the encoding of the file
    - etc.
    your XML may declare a charset itself that is not utf-8. Make sure you look at it.

    I can't think of any ways offhand to check whether your xml is properly encoded as UTF-8. I believe w3c.org offers xml validators. Try googling it.

    Lastly, you may be handling everything right in your code but there might be something finicky going on at the remote server that is hosting the WSDL gateway. It's very helpful to check error logs over there too.

      Thanks!!
      No, I haven't figured it out yet, but I just wanna thank you for taking the time to answer.

      One thing that worries me though, is that I can't even send a string generated
      from the same function that calls the soap server:

      $xmlfile = '<?xml version="1.0" encoding="UTF-8"?><ANSOEGNING></ANSOEGNING>';

      This string is the minimum required xml to be able to pass their parser.

      The file I'm sending it from as UTF-8. This should then be a UTF-8 file ?

      Sending this string disconnects me from my server, and no output is given. By the way, my server is not the soap server, it is the server that generates the client. The Soap server is external https.

        Schnix;10974586 wrote:

        Thanks!!
        No, I haven't figured it out yet, but I just wanna thank you for taking the time to answer.

        You're welcome. Just trying to pass on some of the help I've received myself.

        Schnix;10974586 wrote:

        The file I'm sending it from as UTF-8. This should then be a UTF-8 file ?

        Well, all of the characters that you have used in that string appear to be special inasmuch as they are basic ASCII characters -- which just happen to have the same byte encoding in ASCII or ISO 8859-1 or UTF-8 so yes I would imagine it should suffice as a valid UTF-8 file.

        If you're really concerned about making sure your XML is valid, I strongly recommend googling for XML Validator or WSDL validator. W3C.org has some good ones. The basic idea is that you must validate your XML or WSDL against a schema or DTD -- these are themselves documents which describe what kind of XML or WSDL is acceptable for a particular purpose.

        Schnix;10974586 wrote:

        Sending this string disconnects me from my server, and no output is given. By the way, my server is not the soap server, it is the server that generates the client. The Soap server is external https.

        I'm not sure what you mean by 'disconnects you from your server' ? Are you running the script from the command line using SSH or something? "no output" i understand -- that's why I told you to crank up the error reporting. When PHP croaks and fails to output anything, it's usually because error_reporting is turned down or off OR display_errors is Off.

          Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error.

          This is what Chrome is telling me. Other browsers just give the disconnected by server message.

          My local server (Vmware WS7) instantiates the soap client. And then __SoapCall

          In this process of this, my web browser outputs this message. (Yes, there is actual output to be made)

          Hence, error reporting in PHP has no effect. (It was turned on by the way).

            I think that PHP error reporting does matter. If display_errors is OFF or if error_reporting is turned OFF then when PHP experiences a problem, it will halt without outputting any thing at all and -- because it's finished executing -- will disconnect your client because there's nothing left to talk about.

            If you are using Chrome to visit your local server and getting weird behavior, you may want to try executing your script from the command line to see if it behaves any differently or reports any errors. If error_reporting and display_errors are not ratched up to show you what's wrong, it too will just die without giving any reason. The point of error reporting is to have PHP tell you what went wrong.

            You might also want to alter your script to use try/catch to see if you can catch the exception.

            try {
                     $response = parent::__soapCall("AnsoegningGem", $request = array(
                                                                        'Brugernavn' => "Myrealusername",
                                                                             'Password' => "Myrealpassword",
                                                                           'AnsoegningInd' => $xmlfile)); 
            } catch (Exception $e) {
              die('there was an exception:' . $e->getMessage());
            }
            

            Not sure what else to tell you. So far I've only seen one line of code. The presence of parent::__soapCall suggests that you have some kind of deep object hierarchy so I'm not particularly excited about digging through it. On the other hand, I have no idea what your code is doing.

              Write a Reply...