I try to create a nusoap web service (I use xampp and .net beans) and connect to it using a C# app (use visual studio). but I encounter this error:
{"Server returned an invalid SOAP Fault. Please see InnerException for more details."}
the inner error is:
{"Element 'faultstring' with namespace name '' was not found. Line 6, position 126."}
As this source suggested I changed properties order for function serialize()
in class.soap_fault.php
file but it still gives the same error.
I tried restarting the computer so I now it is not a catch problem.
Also the only other change I made in nusoap library was changing var $soap_defencoding = 'ISO-8859-1';
to var $soap_defencoding = 'UTF-8';
in nusoap.php
file to solve encoding problem.
in C# I have the following code:
SR1.demoPortTypeClient client = new SR1.demoPortTypeClient();
var result = client.gettext("hello");
MessageBox.Show("*" + result + "*");
and in php:
<?php
require 'lib/nusoap.php';
$server=new nusoap_server();
$server->configureWSDL("demo");
$namespace = "demo";
$server->wsdl->schemaTargetNamespace = $namespace;
$server->register(
"gettext",//name of function
array("txt"=>'xsd:string'),//inputs
array("return"=>'xsd:string'),//outputs
$namespace,// namespace
false,// soapaction (use default)
'rpc',// style: rpc or document
'encoded',// use: encoded or literal
'Return same text'// description for method
);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
where gettext
function is:
<?php
function gettext($txt)
{
return $txt;
}
current serialize()
function is:
function serialize(){
$ns_string = '';
foreach($this->namespaces as $k => $v){
$ns_string .= "
xmlns:$k=\"$v\"";
}
$return_msg =
'<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
'<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">
".
'<SOAP-ENV:Body>'.
'<SOAP-ENV:Fault>'.
$this->serialize_val( $this->faultcode, 'faultcode' ) .
$this->serialize_val( $this->faultstring, 'faultstring' ) .
$this->serialize_val( $this->faultactor, 'faultactor' ) .
$this->serialize_val( $this->faultdetail, 'detail' ) .
'</SOAP-ENV:Fault>'.
'</SOAP-ENV:Body>'.
'</SOAP-ENV:Envelope>';
return $return_msg;
}
I expected changing order of properties solves the problem, however I still receive the same error. I searched a lot but couldn't find any other solve for the error.