SOAP: HTTP Bad Request - php

My website is on windows azure web-app. I am using below SOAP message.
$soap_client = new SoapClient("http://ip_address/service.asmx?WSDL", array("trace" => true));
$params = new \SoapVar('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Beneficiary_Address1 xmlns="" />
<Beneficiary_Address2 xmlns="" />
<Beneficiary_Address3 xmlns="" />
<Beneficiary_ZIP_Code xsi:nil="true" xmlns="" />
<Beneficiary_EmailID xsi:nil="true" xmlns="" />
<Beneficiary_Contact_No xmlns="" />
</soap:Body>
</soap:Envelope>', XSD_ANYXML);
try{
$response = $soap_client->__soapCall('RemittanceService', array($params));
highlight_string($soap_client->__getLastRequest());
}
catch(SoapFault $fault){
die("SOAP Fault: fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}
And it's giving me this fault message:
fault code: HTTP, fault string: Bad Request
I don't know what does it mean? Let me know if you need more information.
Thanks.
Stack Trace
SoapFault exception: [HTTP] Bad Request in /var/www/mtes/public_html/application/controllers/bank_api_pnb.php:146
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://124.124....', 'http://tempuri....', 1, 0)
#1 /var/www/mtes/public_html/application/controllers/bank_api_pnb.php(146): SoapClient->__soapCall('RemittanceServi...', Array)
#2 [internal function]: Bank_api_pnb->test()
#3 /var/www/mtes/public_html/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array)
#4 /var/www/mtes/public_html/index.php(220): require_once('/var/www/mtes/p...')
#5 {main}

The path '/var/www/mtes/...' is not valid, it is the web root on Linux. Web root on Azure Apps is wwwroot, when you migrate to Azure Apps, you may need to change configuration, and application settings to point to correct web root. If you have hard coded paths, you need to change them in code as well.

SoapFault is a PHP class, http://php.net/manual/en/soapfault.soapfault.php, the object $fault must have $faultcode and $faultstring when created,
$faultactor, $detail , $faultname, and $headerfault are optional, default to empty.
What you see from exception,
$faultcode is "soap:Server",
$faultstring is "An exception is thrown by the Orchestration schedule".
For debugging, you can add var_dump($fault) in catch statement, it could provide you more info, such as $faultactor, $detail , $faultname, and $headerfault.

Related

PHP SOAP Clients http headers Error

I need to consume a web service https://www.example.com/example.svc?wsdl in PHP. For this purpose, I am using PHP SOAP client. The code snippet like below:
$client = new SoapClient("https://www.example.com/example.svc?wsdl",
array('soap_version' => SOAP_1_2,
'location'=>'https://www.example.com/example.svc',
'login'=> '#####',
'password'=> '#######',
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'encoding'=>'UTF-8',
'connection_timeout' => 500,
'keep_alive' =>false));
$client->__call('getProductList',array());
However, when I run this its through following error:
Warning: SoapClient::__doRequest(): SSL: The operation completed successfully. in E:\location\test1.php on line 37
Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in E:\location\test1:37 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://travius...', 'Travius/ITraviu...', 2, 0) #1 E:\location\test1(37): SoapClient->__call('getProductList', Array) #2 {main} thrown in E:\location\test1.php on line 37
I am struggling several days to solve the error but can't figure out. I tried the different solution in stack overflow like 'keep_alive' =>false, connection_timeout but nothing works.
I also try with php nusoap library. its request and response are like following:
Error
HTTP Error: Unsupported HTTP response status 400 Bad Request (soapclient->response has contents of the response)
Request
POST /#####.svc?wsdl HTTP/1.0
Host: #####.#####.eu
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: application/soap+xml;charset=UTF-8; charset=UTF-8
SOAPAction: ""
Authorization: Basic RGVtb2FwaTpEdXE1dmRWdA==
Content-Length: 529
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><GetProduct><parameters><intProductID xsi:type="xsd:int">1266</intProductID><lang xsi:type="xsd:string">CN</lang></parameters></GetProduct></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 02 Oct 2017 16:03:04 GMT
Content-Length: 0
Please note that this web service works fine in .Net application.
Any help highly appreciated. Thanks in advance.
Judging from the error that you posted in your question please change the following line.
$client->__call('getProductList',array());
with something like this
$client = false;
try {
$client = new SoapClient("https://www.example.com/example.svc?wsdl",
array('soap_version' => SOAP_1_2,
'location'=>'https://www.example.com/example.svc',
'login'=> '#####',
'password'=> '#######',
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'encoding'=>'UTF-8',
'connection_timeout' => 500,
'keep_alive' =>false));
} catch (Exception $e) {
exit("SoapClient Error \"".$e->getMessage()."\"");
}
if(!empty($client)) {
try {
$soapResponse = $client->__soapCall('getProductList',array());
var_dump($soapResponse);
} catch (SoapFault $e) {
exit("Error using method \"getProductList\" having errorCode \"".$e->faultcode."\"");
}
}
I don't know what php version you use (you have not posted relevant information) but i think in your case _call is deprecated.
Calling this method directly is deprecated. Usually, SOAP functions
can be called as methods of the SoapClient object; in situations where
this is not possible or additional options are needed, use
SoapClient::__soapCall().
Hi Did you try to write your soap header as wssecurity you can see samples
or this in stackoverflow

Cannot read from non-readable stream

I am trying to download an external file using guzzle. This is the code that I use:
// $url is a URL I receive from Openload's API request
$url = 'https://abvzps.example.com/dl/l/4spxX_-cSO4/The+quick+brown+fox.mp4';
$path = storage_path('app/remote-uploads/test.mp4');
$client = new Client();
$client->get($url, ['sink' => $path]);
The code works and downloads from localhost just fine, but when I push it to production I receive this error:
[2017-03-25 19:08:06] production.ERROR: RuntimeException: Cannot read from non-readable stream in /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/psr7/src/Stream.php:208
Stack trace:
#0 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php(132): GuzzleHttp\Psr7\Stream->read(120)
#1 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php(105): GuzzleHttp\Exception\RequestException::getResponseBodySummary(Object(GuzzleHttp\Psr7\Response))
#2 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#3 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#4 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#5 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#6 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(246): GuzzleHttp\Promise\TaskQueue->run(true)
#7 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(223): GuzzleHttp\Promise\Promise->invokeWaitFn()
#8 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(267): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(225): GuzzleHttp\Promise\Promise->invokeWaitList()
#10 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#11 /var/www/vhosts/clooud.tv/httpdocs/vendor/guzzlehttp/guzzle/src/Client.php(129): GuzzleHttp\Promise\Promise->wait()
...
I am not quite sure how to go about this and would really appreciate any help!
It's hard to say something without the real URL and debugging.
Just set a breakpoint before the exception and take a look at the response. IMO it should contain an error, but I have no idea, which one exactly.

SOAP Envelope Element is not declared

I have an issue with a SOAP request I'm sending to an external ASP Web Service. I have used both SoapUI and PHP's SoapClient class, and both times the same issue occurs - an error that tells me The 'http://www.w3.org/2003/05/soap-envelope:Envelope' element is not declared.
My Request to 'GetStudentEntitlement'
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:adm="http://dest.gov.au/Heims/Admin/" xmlns:heim="http://dest.gov.au/Heims/">
<soap:Header/>
<soap:Body><adm:GetStudentEntitlement>
<heim:entitlementRequest>
<heim:RequestControlTable>
<heim:RequestId>CDD1E704-1298-4D42-AAD9-0031BB90329F</heim:RequestId>
<heim:ClientOrganisationCode>7591</heim:ClientOrganisationCode>
<heim:RequestLocalDateTime>2015-08-10T00:00:00</heim:RequestLocalDateTime>
</heim:RequestControlTable>
<heim:GetEntitlementIn>
<heim:RecordId>CDD1E704-1298-4D42-AAD9-0031BB90329F</heim:RecordId>
<heim:Chessn>1344</heim:Chessn>
<heim:FamilyName>Bassett</heim:FamilyName>
<heim:BirthDate>1988-05-21</heim:BirthDate>
</heim:GetEntitlementIn>
</heim:entitlementRequest>
</adm:GetStudentEntitlement>
</soap:Body>
</soap:Envelope>
The response:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Sender</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Heims.WebServices.Extensions.Exceptions.XmlSchemaValidationException: Schema validation errors
at Heims.WebServices.Extensions.SoapFilterExtension.ValidateXmlMessage(SoapMessage message, WebMethodSettings methodSettings) in c:\Userdata\HEIMS.NET\Source\Development\WebService\Heims.WebService.Common\Extensions\SoapFilterExtension.cs:line 408
at Heims.WebServices.Extensions.SoapFilterExtension.ProcessMessageBeforeDeserialise(SoapMessage message) in c:\Userdata\HEIMS.NET\Source\Development\WebService\Heims.WebService.Common\Extensions\SoapFilterExtension.cs:line 200
at Heims.WebServices.Extensions.SoapFilterExtension.ProcessMessage(SoapMessage message) in c:\Userdata\HEIMS.NET\Source\Development\WebService\Heims.WebService.Common\Extensions\SoapFilterExtension.cs:line 173
at System.Web.Services.Protocols.SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException)
at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</soap:Text>
</soap:Reason>
<detail>
<ValidationError>
<RecordId/>
<Element>Envelope</Element>
<Line>1</Line>
<Column>2</Column>
<Description>The 'http://www.w3.org/2003/05/soap-envelope:Envelope' element is not declared.</Description>
</ValidationError>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
I have tried adding and removing the trailing / on the :soap declaration, as well as trying both the 1.1 and 1.2 SOAP versions offered by this web service.
This endpoint request to 'Ping' works correctly:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:adm="http://dest.gov.au/Heims/Admin/">
<soap:Header/>
<soap:Body>
<adm:Ping/>
</soap:Body>
</soap:Envelope>
The result is returned as expected:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PingResponse xmlns="http://dest.gov.au/Heims/Admin/">
<PingResult>Heims web services pinged. DateTime = 2015-08-10 11:11:00:05</PingResult>
</PingResponse>
</soap:Body>
</soap:Envelope>
So why would the code for one request (the ping) work perfectly, while the other request (GetStudentEntitlement) fails? Both have the soap:Envelope declaration, but the Ping request works fine.
I have also tried using xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" in the soap:Envelope element, but the error remained.
Is it possible that this is a server-side issue from the Web Service itself? Or is something simply going wrong in my code?
Answering my own question.
I contact the Government IT Assistance directly, and had them send me a code example. They were using a highly unusual and modified form of <soap wrapper, forcing me to manually generate the XML using SimpleXMLElement and submit to the Web Service using a wrapped SoapVar with the XSD_ANYXML type.
Did you get any solution to this...
I have encountered same problem today while converting UTL_DBWS utility (oracle plsql) to APEX utilities to make calls to HEIMS web service.
Ping worked but GetStudentEntitlements and AllocateStudentChessn both are failing with same envelop error.
Regards
RC

SOAP Client php

I'm need a little help about WS SOAP Client in PHP.
I have a WS SOAP, restrict to my IP, but I don know almost anything about SOAP, I've already use SOAP with rails a long time ago.
If I access the SOAP server from my browser using this: http://thedomain.com/wssitedsv/site.asmx/RetornaGanhadores
The server return me the correct XML.
If I access the SOAP server from my browser using this:
http://thedomain.com/wssitedsv/site.asmx?wsdl
The server return a xml with configuration of the SOAP
In the PHP I'm doing it:
$url = "http://thedomain.com/wssitedsv/site.asmx?wsdl";
$client = new SoapClient($url);
$return = $client->RetornaGanhadores(NULL);
echo $return;
And I'm getting this error:
PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /Users/sidnei/Sites/suasorte/scripts/get_data.php:15
\\nStack trace:
\\n#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://192.168....', 'https://www.tte...', 1, 0)
\\n#1 /Users/sidnei/Sites/suasorte/scripts/get_data.php(15): SoapClient->__call('RetornaGanhador...', Array)
\\n#2 /Users/sidnei/Sites/suasorte/scripts/get_data.php(15): SoapClient->RetornaGanhadores(NULL)
\\n#3 /Users/sidnei/Sites/suasorte/index.php(2): include('/Users/sidnei/S...')
\\n#4 {main}
\\n thrown in /Users/sidnei/Sites/suasorte/scripts/get_data.php on line 15
I can get all methods from Server using this:
$url = "http://thedomain.com/wssitedsv/site.asmx?wsdl";
$client = new SoapClient($url);
$return = $client->__getFunctions();
print_t $return;
What I am doing wrong to use this SOAP server?
How use a SOAP Server in PHP?
I appreciate any help.
Thanks

php consume WCF SSL SOAP Client 1.2

Im having some problems consuming a wsHttpBinding WCF from PHP. I originally tried to use SOAP1.2 but couldnt get it to specify the WS Action.
I downloaded the nusoap library. I was originally getting an error saying that the webservice wouldnt accept the data due to a type mismatch (text/xml instead of the expected application/soap+xml). I managed to make changes to nusoap.php to send the data as application/soap+xml). Now that doesnt throw an error, i get 400 bad request error from the server.
I can consume the service from WCFTestClient and also from SOAPUI without any messing around, but just cannot get it to fly from PHP. I even copied the entire soap envelope from SOAPUI and set the $soapmsg in nusoap.php to be exactly that and it still fails.
So anyone want to offer some guidance.
EDIT
This is the code i was trying in SOAP 1.2
$params = array("soap_version"=> SOAP_1_2,
"trace"=>1,
"exceptions"=>0,
);
$client = #new SoapClient('https://localhost/wcftest/Service.svc?wsdl',$params);
$retval = $client->GetData(array('value'=>'stuff'));
if (is_soap_fault($retval)) {
trigger_error("SOAP Fault: (faultcode: {$retval->faultcode}, faultstring: {$retval->faultstring})", E_USER_ERROR);
}
EDIT #2
This is the code that works out of SOAPUI
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://tempuri.org/IService/GetData</wsa:Action></soap:Header>
<soap:Body>
<tem:GetData>
<!--Optional:-->
<tem:value>stuff</tem:value>
</tem:GetData>
</soap:Body>
</soap:Envelope>
After adding the SoapHeaders manually as mentioned by Gords link below i get this as the __last_request when debugging with netbeans and still the same error
"<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/">
<env:Header>
<ns1:Action>http://tempuri.org/IService/GetData</ns1:Action>
</env:Header>
<env:Body><ns1:GetData><ns1:value>stuff</ns1:value></ns1:GetData></env:Body></env:Envelope>
any advice??
Thanks!
Andy
Ok so i got this to work. Thanks to Gord for making me double check stuff that i had overlooked earlier on.
I ended ditching nusoap and just sticking with with SOAP 1.2. Here is my php code
//Declare some paramaters for our soapclient. Need to make sure its set to soap 1.2
$params = array("soap_version"=> SOAP_1_2,
"trace"=>1,
"exceptions"=>0,
);
//Create the soap client
$client = new SoapClient('https://localhost/wcftest/Service.svc?wsdl',$params);
//add some WSAddressing Headers in. Ensure that you have the Namespace as the address if you are using wsHttpBinding on the endpoint
//This was the step that took me the longest to figure out!
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing','Action','http://tempuri.org/IService/GetData',true);
//Add the headers into the client
$client->__setSoapHeaders($actionHeader);
//Make the call and pass in the variables that we require to go to the server
$retval = $client->__soapCall('GetData',array('value'=>'stuff'));
//Some Error Catching
if (is_soap_fault($retval)) {
trigger_error("SOAP Fault: (faultcode: {$retval->faultcode}, faultstring: {$retval->faultstring})", E_USER_ERROR);
}
and the working envelope
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<ns2:Action env:mustUnderstand="true">http://tempuri.org/IService/GetData</ns2:Action>
</env:Header>
<env:Body>
<ns1:GetData/>
</env:Body>
</env:Envelope>
and the web.config file from the WCF Service
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="Timeforce" connectionString="Data Source=apps.ziptrek.com;Initial Catalog=qqest;User ID=qqest; Password=qqest;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="Service1">
<endpoint address="https://localhost/wcftest/Service.svc" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="IService"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service1">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="httpsService1">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

Categories