Link to home
Start Free TrialLog in
Avatar of Codeforlife
CodeforlifeFlag for South Africa

asked on

Consuming ASPNET WSDL service using PHP

Consuming ASPNET WSDL service using PHP
Hi Experts,
having some serious issues getting this one right. I am writing a PHP web app that needs to post an xml to an ASPNET WSDL service. Upon submitting data via PHP service it gives me an error "SoapFault exception: [s:Client] An error has occurred during service execution halting any further processing."
I then decided to use ReadyAPI and the error it gives is "HTTP/1.1 415 Cannot process the message because the content type 'multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_0_2905742.1520010170903"' was not the expected type 'text/xml; charset=utf-8'."

Really baffled with this one. Have tried so many different soap codes to submit data and same response. any suggestions?
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

could it be as simple as appending the   "; charset=utf-8'" to the type when submitting the request?
Avatar of Codeforlife

ASKER

thx but i got it working with ReadyAPI. when i look at the RAW request sent by ReadyAPI which works it looks as follows: masked out some data due to confidentiality

POST https: test.url.com
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://ns.test.com"
Content-Length: 1066
Host: webservices.test.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_144)

<soapenv:Envelope xmlns:soapenv="http://schemas.xml.org/soap/envelope/" xmlns:ns="http://ns.test.co.za/server/test">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:call>
         <!--Optional:-->
         <ns:xmlData><![CDATA[<?xml version="1.0" encoding="UTF-8" ?> <test>    <mode>LIVE</mode>                 <title>Mr</title>                 <firstname>Mark</firstname>                 <lastname>Williams</lastname>                 <id>1234567890123</id>                 <homecode>011</homecode>                 <hometel>1111111</hometel>                 <workcode>011</workcode>                 <worktel>1111111</worktel>                 <mobile>0881234567</mobile>                 <email>test@test.com</email>                 <comment>THIS IS A COMMENT</comment>                 <source>S</source>                 <notes>THIS I A NOTE</notes>                 <language>E</language>                 <product>E</product> </test> ]]></ns:xmlData>
      </ns:call>
   </soapenv:Body>
</soapenv:Envelope>

Now how do i translate this into my PHP code when call using soap.
Can you try the same request from your PHP and post the XML?  Need to compare the non-working and the working.
from:
https://solaajayi.wordpress.com/2013/12/04/beginners-guide-to-consuming-a-web-service-using-php-soapclient/

$url = “http://www.webservicex.com/globalweather.asmx?wsdl“;
$client = new SoapClient($url);
$res = $client->GetWeather(array(‘CityName’ => ‘Lagos’, ‘CountryName’ => ‘Nigeria’));

Open in new window


Using the above you can see they're just converting the parameters into an array.
http://www.webservicex.com/globalweather.asmx?op=GetWeather
no luck. the issue seems to be the way i am submitting the xml data from my php code. perhaps the way i am declaring my xml data in my php coding is the issue? what is the correct layout/format that my XML data need to be in? the way i am doing it at the moment
I declare the XML data as a variable

//xml submission sample
$xmlstr =
'<?xml version="1.0" encoding="UTF-8" ?>
<test>
   <mode>LIVE</mode>
                <title>Mr</title>
                <firstname>mark</firstname>
                <lastname>williams</lastname>
                <id>1234567890123</id>
                <homecode>011</homecode>
                <hometel>3415285</hometel>
                <workcode>011</workcode>
                <worktel>3415285</worktel>
                <mobile>0881234567</mobile>
                <email>test@test.com</email>
                <comment>THIS IS A COMMENT</comment>
                <source>c</source>
                <notes>THIS I A NOTE</notes>
                <language>E</language>
                <product>a</product>
</test>';

then my php soap code

$wsdl   = "https://webservices.test.com/services?wsdl";
$client = new SoapClient($wsdl);

try
{
    $xmlstr = $client->Send("$inputxml));
   
    echo $response_param;
   
  }
catch (Exception $e)
{
    echo "<h2>Exception Error!</h2>";
    echo $e->getMessage();
}
Is "Send" the name of your webservice function?

Also:
$client->Send("$inputxml));

it looks like you're passing in a different variable?

In researching I stumbled across: https://stackoverflow.com/questions/16595789/sending-xml-input-to-wsdl-using-soapclient


Which looks like they're using the below to pass raw xml:
$params = new stdClass();
$params->xml = $xmlr->asXML();

Open in new window


Modifying for your code:
$params = new stdClass();
$params->xml = $xmlstr ->asXML();

$result = $client->Send($params);

Open in new window

sorry i made a type. herewith correct code. but adding that xml statement as per above it breaks the code where the output is not displayed and the logout function on my page is removed- so any code below this xml statement does not run. see my code. The WSDL service requires it to be in XML

$wsdl   = "https://webservices.testservice.svc?wsdl";
$client = new SoapClient($wsdl)

$params = new stdClass();
$params->xml = $xmlstr ->asXML();

try
{
$response_param = $client->Send($xmlstr);
   
    echo $response_param;
   
   }
catch (Exception $e)
{
    echo "<h2>Exception Error!</h2>";
    echo $e->getMessage();
}
$response_param = $client->Send($xmlstr);

should be

$response_param = $client->Send($params);
sorry made another typo when i copied over my code- that is in fact my code. and it breaks any code beneath it.  this is the raw request data showing in ReadyAPI that works fine. Do i need to put of any of the below except XML data in my php code?

POST https: test.url.com
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://ns.test.com"
Content-Length: 1066
Host: webservices.test.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_144)

<soapenv:Envelope xmlns:soapenv="http://schemas.xml.org/soap/envelope/" xmlns:ns="http://ns.test.co.za/server/test">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:call>
         <!--Optional:-->
         <ns:xmlData><![CDATA[<?xml version="1.0" encoding="UTF-8" ?> <test>    <mode>LIVE</mode>                 <title>Mr</title>                 <firstname>Mark</firstname>                 <lastname>Williams</lastname>                 <id>1234567890123</id>                 <homecode>011</homecode>                 <hometel>1111111</hometel>                 <workcode>011</workcode>                 <worktel>1111111</worktel>                 <mobile>0881234567</mobile>                 <email>test@test.com</email>                 <comment>THIS IS A COMMENT</comment>                 <source>S</source>                 <notes>THIS I A NOTE</notes>                 <language>E</language>                 <product>E</product> </test> ]]></ns:xmlData>
      </ns:call>
   </soapenv:Body>
</soapenv:Envelope>
You need to capture the raw request that the PHP is sending.  Do you have wireshark?
its a hosted server at an ISP so i dont have the option to install wireshark. is there any other way to capture/ouput the raw request from my service?
Ok i have made some progress. but- upon submitting my xml string to to WSDL service it still rejects it and when i output the response all my "<" and ">" signs are being escaped and i think the wsdl servivce rejects this. I have tried the anyxml command and this rectifies this but then it distorts the soap envelope with parameters that were never there. I then turned to CURL and also having huge issues, is constantly says endpoint not found error 404? Any help will be much appreciated.
sorted. issue was with my sumbission string- had some fields missing. used soap, works perfectly
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.