Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using PHP to call a WCF web service with multiple bindings

Tags:

php

soap

wcf

I have a WCF web service which allows both Basic HTTP and WS-HTTP clients, both over HTTPS using user name & password authentication. This is achieved with two bindings on the same service.

So, the service is at https://foo.com/Service.svc, the Basic HTTP (SOAP 1.1) endpoint is https://foo.com/Service.svc/Unp11, and the WS-HTTP (SOAP 1.2) endpoint is https://foo.com/Service.svc/Unp .

A client is trying to access this web service via PHP 5, using its built-in SOAP support, and is having trouble connecting to the service. He keeps getting an HTTP 400 (Bad Request) response, which tends to happen if the SOAP message is badly formed, or a SOAP 1.1 message is sent to a SOAP 1.2 endpoint (or vice versa).

I only know basic PHP so I'm having trouble helping him. I know you can create a client by doing

$client = new SoapClient('https://foo.com/Service.svc?wsdl');

but how do you specify the binding/endpoint? Are there any known issues achieving all this with PHP?

UPDATE

Ok, so I can use PHP to connect to the WCF service ok (specifying the SOAP version in the SoapClient constructor), and calling $client->__getFunctions() returns a correct list of all the web service operations.

When I try to call one using $client->__soapCall, the page just sits there loading for quite a while, and eventually returns the error "Error Fetching http headers". What exactly is this supposed to mean and how do I fix it? (Consuming the service from .Net client works perfectly.)

like image 377
Graham Clark Avatar asked Jul 27 '09 14:07

Graham Clark


1 Answers

Just ran into this today, creating a WCF with multiple bindings for a PHP caller. Setting the location appears to allow for both the WSDL version of PHP's SoapClient and specifying a binding to use.

WCF config is (1 service with 2 bindings wsHttp and basicHttp), pretty straight-forward.

PHP code:

$client = new SoapClient("http://example.com/service.svc?wsdl");
$client->__setLocation("http://example.com/service.svc/basic");
$response = $client->MethodName(array( "paramName" => "paramValue" ... ));
like image 175
Altai Avatar answered Oct 10 '22 23:10

Altai