Uncaught Soapfault Exception: [Versionmismatch]

Asked

Viewed 1,259 times

0

I’m testing a Web Service simple that sends and receives a string, however the server (Apache 2) returns the following error message:

Fatal error: Uncaught Soapfault Exception: [Versionmismatch] Wrong Version in /var/www/html/client.php:7 Stack trace: #0 /var/www/html/client.php(7): Soapclient->__call('helloName', Array) #1 {main} thrown in /var/www/html/client.php on line 7

Below are the scripts:

Application on the server with PHP

<?php  

function helloName($name)
{

    return 'Hello ' . $name;

}

$WSDL = 'ws.asmx';
$server = new SoapServer($WSDL);

$server->addFunction('helloName');

if($_SERVER['REQUEST_METHOD'] == 'POST')
{

    $server->handle();

} else 
{

    foreach ($server->getFunctions() as $funcs) {

        print $funcs . ' <br> ';

    }

}


?>

WSDL

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:tns="http://localhost/"   
 xmlns:wsdl="http://www.w3.org/ns/wsdl"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="webservices"
 targetNamespace="http://localhost/">

<wsdl:types>

    <xsd:schemas targetNamespace="http://localhost/">

        <xsd:element name="parametroin">

            <xsd:simpleType>

                <xsd:element name="name" type="xsd:string"/>

            </xsd:simpleType>

        </xsd:element>

        <xsd:element name="parametroout">

            <xsd:simpleType>

                <xsd:element name="nameResponse" type="xsd:string"/>

            </xsd:simpleType>

        </xsd:element>

    </xsd:schemas>

</wsdl:types>

<wsdl:message name="getHelloName">

    <wsdl:part name="name" element="parametroin" type="xsd:string"/>

</wsdl:message>

<wsdl:message name="getHelloNameResponse">

    <wsdl:part name="name" element="parametroout" type="xsd:string"/>

</wsdl:message>

<wsdl:portType name="helloNamePortType">

    <wsdl:operation name="helloName">

        <wsdl:input message="getHelloName"/>

        <wsdl:output message="getHelloNameResponse"/>

    </wsdl:operation>

</wsdl:portType>

<wsdl:binding name="helloNameBinding" type="tns:helloNamePortType">

    <wsdl:operation name="helloName">

        <wsdl:input message="getHelloName">

            <soap:body parts="name" use="literal"/>

        </wsdl:input>

        <wsdl:output message="getHelloNameResponse">

            <soap:body parts="name" use="literal"/>

        </wsdl:output>

    </wsdl:operation>

</wsdl:binding>

<wsdl:service name="ws">

    <wsdl:port name="getHelloport" binding="tns:helloNameBinding">

        <soap:address location="http://localhost/ws.asmx"/>

    </wsdl:port>

</wsdl:service>

Protocol SOAP captured by Wireshark

<?xml version="1.0" encodind="utf-8"?>
<SOAP-Env:envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope"> 
     <SOAP-ENV:Body>
          <body>
             nome
          </body>
      </SOAP-ENV:Body>
  <SOAP-ENV:envelope>

Script that tries to connect the server.

 <?php

   $wsdl = 'ws.asmx';
   $options = array('version' => 1, 'encoding' => 'utf-8', 'SoapVersion' => SOAP_1_2);
   $client = new SoapClient($wsdl, $options);
   print_r($client->__getFunctions());
   $result = $client->__call('helloName', array('nome'));

   print $result;


?>

1 answer

0

This error is related to the version of the SOAP protocol used.

In your script the $options property should be soap_version and not soapversion. If it still doesn’t work you can try SOAP_1_1 instead of SOAP_1_2.

  • I was able to solve the problem. I was using apache2 on Ubuntu and when I ran the same code on Wamp windows ran good. But still thanks for the help.

  • Probably because they use different defaults for the SOAP version. In fact, hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.