如何使用php执行Web服务

时间:2012-01-10 17:49:19

标签: php web-services

我需要从php页面执行Web服务

网络服务位于以下网址

https://www.agemni.com/AgemniWebservices/service1.asmx

Web Service使用SOAP协议来交换消息。

WSDL信息可以位于https://www.agemni.com/AgemniWebservices/service1.asmx?WSDL

我们需要使用的服务功能是 ValidateEntity

// ValidateEntity(“username”,“password”,“companyID”,2,键,值)

那么,我如何执行此Web服务并从我的php页面获取结果

4 个答案:

答案 0 :(得分:0)

请参阅php.net的soap调用帮助:

http://www.php.net/manual/en/soapclient.soapcall.php

答案 1 :(得分:0)

您需要使用PHP的SOAP库......

http://www.php.net/manual/en/soapclient.soapcall.php

答案 2 :(得分:0)

一个简单的例子,希望它有所帮助...

$service1 = new SoapClient('https://www.agemni.com/AgemniWebservices/service1.asmx');

//here you instanciate your object with those properties
$entity = new Entity();
$entity->strUsername = 'José';
$entity->strPassword = '123';
$entity->strCompanyName = 'Somethin';
$entity->0 //because your type is int

$res = $service1->ValidateEntity($entity);//here you send the information to your service's method, if I'm not mistaken, it must be a object

$res->ValidateEntityResult;//this is the return of your service.

正如我所说,这很简单但有效。

答案 3 :(得分:0)

对于https WebServices,您需要启用openssl扩展。 WS使用.net意味着类使用类型提示,因此您需要创建ValidateEntity类,这里是代码:

$ws = new soapclient('https://www.agemni.com/AgemniWebservices/service1.asmx?wsdl');
class ValidateEntity {
    public $strUsername,
    $strPassword,
    $strCompanyName,
    $objecttype;
    }

$parameters = new ValidateEntity();
$parameters->strUsername = 'username';
$parameters->strPassword = 'password';
$parameters->strCompanyName = 'company';
$parameters->objecttype = 1;
echo '<pre>';
print_r($ws->ValidateEntity($parameters));
echo '</pre>';