SOAP Web Service on ASP server consumed via PHP
I'm trying to use a Web Service using PHP and SOAP. The Web Service is built in .NET and hosted on an ASP server. I'm using the following code to interact with the API but I keep getting an error with parsing WSDL. The PHP UNIX server has an SSL certificate, the web service host also has an SSL certificate and I'm using https to initiate the transaction.
This particular API call requests a string for a membership number:
$wsdl='https://domain.com/ws.asmx?wsdl';
$client=new SOAPClient($wsdl, array('exceptions'=>0));
$result=$client->IsMemberCurrent('123456789');
Error:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'domain/ws.asmx?wsdl' : Start tag expected, '<' not found in index.php on line 4
I can see the WSDL contents but the error message I'm getting via PHP suggests it either can't see or can't process the WSDL file?
SOAP 1.2 service description:POST /SubscriberAPI.asmx HTTP/1.1
Host: subdomain.domain.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="u开发者_JAVA技巧tf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<IsMemberCurrent xmlns="http://www.domain.com/">
<MembershipNo>string</MembershipNo>
</IsMemberCurrent>
</soap12:Body>
</soap12:Envelope>
It seems that you cannot access the WSDL file. So you need to diagnose the issue.
Try
echo htmlentities(file_get_contents($wsdl));
It will give you better insight as to what PHP gets as a response.
Once you have got the SoapClient working your next line of code will not work as expected.
You need wrap your parameter in an associative array otherwise the web service will not recognize it.
Also the response returned by the .NET web service will be a IsMemberCurrentResponse object, which contains a IsMemberCurrentResult, so you need to replace your last line with the following.
$params = array('MembershipNo'=>'1234567890');
$response = $client->IsMemberCurrent($params);
$result = $response->IsMemberCurrentResult;
精彩评论