Sarvand
Sarvand

Reputation: 41

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

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.

Upvotes: 3

Views: 6394

Answers (2)

Pooya Hejazi
Pooya Hejazi

Reputation: 9

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();
    }
}

Upvotes: 0

PKeidel
PKeidel

Reputation: 2589

You could try

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

try {
    $client = new SoapClient($url, [
        "soap_version" => SOAP_1_2, // SOAP_1_1
        'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
        'trace' => 1,
        'exception' => 1,
        'keep_alive' => false,
        'connection_timeout' => 500000
    ]);
    print_r($client->__getFunctions());
} catch (SOAPFault $f) {
    error_log('ERROR => '.$f);
}

to verify that your method name is correct.

There you can see the method

VerifyBillPaymentWithAddDataResponse VerifyBillPaymentWithAddData(VerifyBillPaymentWithAddData $parameters)

Next is to check the Type VerifyBillPaymentWithAddData and if the parameter can be an array. Also you could test to call the method via

$client->VerifyBillPaymentWithAddData([
    'UserName' => 12324,
    'Password' => 432123,
    'Bill_Id' => 153585611140,
    'Payment_Id' => 8560103,
]);

or yours except the additional array

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

EDIT: Assuming to https://stackoverflow.com/a/5409465/1152471 the error could be on the server side, because the server sends an header back that is not compatible with SOAP 1.2 standard.

Maybe you have to use an third party library or even simple sockets to get it working.

Upvotes: 5

Related Questions