Codeforlife
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.or g>"; boundary="----=_Part_0_290 5742.15200 10170903"' 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?
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.or
Really baffled with this one. Have tried so many different soap codes to submit data and same response. any suggestions?
could it be as simple as appending the "; charset=utf-8'" to the type when submitting the request?
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</lastna me> <id>1234567890123</id> <homecode>011</homecode> <hometel>1111111</hometel> <workcode>011</workcode> <worktel>1111111</worktel> <mobile>0881234567</mobile > <email>test@test.com</emai l> <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.
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
</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/
Using the above you can see they're just converting the parameters into an array.
http://www.webservicex.com/globalweather.asmx?op=GetWeather
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’));
Using the above you can see they're just converting the parameters into an array.
http://www.webservicex.com/globalweather.asmx?op=GetWeather
ASKER
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</lastna me>
<id>1234567890123</id>
<homecode>011</homecode>
<hometel>3415285</hometel>
<workcode>011</workcode>
<worktel>3415285</worktel>
<mobile>0881234567</mobile >
<email>test@test.com</emai l>
<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();
}
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</lastna
<id>1234567890123</id>
<homecode>011</homecode>
<hometel>3415285</hometel>
<workcode>011</workcode>
<worktel>3415285</worktel>
<mobile>0881234567</mobile
<email>test@test.com</emai
<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:
Modifying for your code:
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();
Modifying for your code:
$params = new stdClass();
$params->xml = $xmlstr ->asXML();
$result = $client->Send($params);
ASKER
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();
}
$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);
should be
$response_param = $client->Send($params);
ASKER
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</lastna me> <id>1234567890123</id> <homecode>011</homecode> <hometel>1111111</hometel> <workcode>011</workcode> <worktel>1111111</worktel> <mobile>0881234567</mobile > <email>test@test.com</emai l> <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>
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
</ns:call>
</soapenv:Body>
</soapenv:Envelope>
You need to capture the raw request that the PHP is sending. Do you have wireshark?
ASKER
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?
ASKER
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.
ASKER
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 TRIALMembers 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.