PHP SoapClient Cannot process the message because the content type 'text/xml;

Viewed 5450

I cannot connect to webservice and send/receive data

Error

HTTP,Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.

Code


    $parameters = [
        'UserName' => 12324,
        'Password' => 432123,
        'Bill_Id' => 153585611140,
        'Payment_Id' => 8560103,
    ];

    $url="https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
    $method = "VerifyBillPaymentWithAddData";

    $client = new SoapClient($url);

    try{

        $info = $client->__call($method, array($parameters));

    }catch (SoapFault $fault){  

        die($fault->faultcode.','.$fault->faultstring);

    }

Notice : not work Soap version 1,1 and other resolve sample for this error in stackoverflow.

2 Answers

Just use the following function. Have fun!

function WebServices($function, $parameters){
        
    $username = '***';
    $password = '***';

    $url = "http://*.*.*.*/*/*/*WebService.svc?wsdl";
    $service_url = 'http://*.*.*.*/*/*/*WebService.svc';
    

    
    $client = new SoapClient($url, [
        "soap_version" => SOAP_1_2,
        "UserName"=>$username, 
        "Password"=>$password,
        "SOAPAction"=>"http://tempuri.org/I*WebService/$function",
        'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
        'trace' => 1,
        'exception' => 1,
        'keep_alive' => false,
        'connection_timeout' => 500000
    ]);
    $action = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', "http://tempuri.org/I*WebService/$function");
    $to = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $service_url);
    $client->__setSoapHeaders([$action, $to]);
    try{
        return $client->__call($function, $parameters);  
    } catch(SoapFault $e){
        return $e->getMessage();
    }
}
Related