Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOAP: HTTP Bad Request

I am getting below error after requesting SOAP call.

fault code: HTTP, fault string: Bad Request

Is this badly formed message?

try{
    $client = new SoapClient("http://ip_add/something.asmx?WSDL", array("trace" => true, 'exceptions' => 1));

    $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>
                    <RemittanceService xmlns="http://tempuri.org/">
                    <CreditTxnMessage xmlns="http://my_url">
                    <Corporate_UID xmlns="">66666</Corporate_UID>
                    <Mandate_Type xmlns="">P</Mandate_Type>
                    <MICR_No xsi:nil="true" xmlns="" />
                    <Instrument_No xsi:nil="true" xmlns="" />
                    <Remitter_Address1 xmlns="">285 enfiled pl</Remitter_Address1>
                    <Remitter_Address2 xmlns="">mississauga</Remitter_Address2>
                    <Remitter_Address3 xmlns="">16y2n4</Remitter_Address3>
                    <Remitter_Country xmlns="">Canada</Remitter_Country>
                    <Remitter_ZIP_Code xsi:nil="true" xmlns="" />
                    <Remitter_EmailID xsi:nil="true" xmlns="" />
                    <Remitter_Contact_No xmlns="" />
                    <Beneficiary_ZIP_Code xsi:nil="true" xmlns="" />
                    <Beneficiary_EmailID xsi:nil="true" xmlns="" />
                    <Beneficiary_Contact_No xmlns="" />
                    <Beneficiary_Bank_Name xmlns="">PNB</Beneficiary_Bank_Name>
                    </CreditTxnMessage>
                    </RemittanceService>
                </soap:Body>
                </soap:Envelope>', XSD_ANYXML);

    $result = $client->__soapCall('RemittanceService', array($params));
    highlight_string($client->__getLastRequest());
}
catch(SoapFault $fault){
    die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}

I don't know what's wrong here.

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}
like image 270
Ronak Patel Avatar asked Jun 26 '15 15:06

Ronak Patel


People also ask

Is a SOAP request an HTTP request?

SOAP is a protocol to exchange XML-based messages, and SOAP should use HTTP to transport those messages, as already explained in the introduction section. On the other hand, HTTP is a communications protocol that transports messages over a network, not like SOAP.

Can you send attachments in SOAP request?

You can send and receive SOAP messages that include binary data (such as PDF files or JPEG images) as attachments. Attachments can be referenced (that is, represented explicitly as message parts in the service interface) or unreferenced (in which arbitrary numbers and types of attachments can be included).

Which of the following is a mandatory element in a SOAP message?

A SOAP message is encoded as an XML document, consisting of an <Envelope> element, which contains an optional <Header> element, and a mandatory <Body> element.


2 Answers

The whole point of the SoapClient is to convert calls to xml; so you shouldn't be doing this manually. Try this instead:

try {
    $client = new SoapClient("http://ip_add/something.asmx?WSDL", array("trace" => true, 'exceptions' => 1));

    $result = $client->RemittanceService(array(
            'CreditTxnMessage' => array(
                    'Corporate_UID' => 66666,
                    'Mandate_Type' => 'P',
                    'MICR_No' => null,
                     /* you get the idea */
                    'Beneficiary_Contact_No' => '',
                    'Beneficiary_Bank_Name' => 'PNB'
            )
    ));

    highlight_string($client->__getLastRequest());
}
catch(SoapFault $fault){
    die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}

The exact format of the parameters and their names would be specified in the WSDL.

like image 78
Sjon Avatar answered Oct 25 '22 00:10

Sjon


Generally a Bad Request response to a SOAP request is returned when the message is not in a good format (invalid header, body, ..) and therefor the document can't be parsed. First of all try to remove the XML version declaration from your SoapVar and see if it fixes the problem (remove the line below):

<?xml version="1.0" encoding="UTF-8"?> 

Alternatively you can always test your Soap requests in tools like SoapUI to make sure they work and then complete your code. If it doesn't work in SoapUI it means there is something wrong with the request. Try to revise the WS and make sure you are sending everything in the correct format (eg. maybe you need to authenticate? SoapHeader? ..)

like image 42
hatef Avatar answered Oct 25 '22 02:10

hatef