如何使用php执行web服务

如何使用php执行web服务,php,web-services,Php,Web Services,我需要从php页面执行web服务 web服务位于以下url中 Web服务使用SOAP协议来交换消息 WSDL信息可位于 该服务中我们需要使用的功能是ValidateEntity //ValidateEntity(“用户名”、“密码”、“公司ID”、2、键、值) 那么,如何执行此web服务并从我的php页面获得结果呢?请参见php.net中的soap调用帮助: 您需要使用PHP的SOAP库 一个简单的例子,希望对你有所帮助 $service1 = new SoapClient('https://

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

web服务位于以下url中

Web服务使用SOAP协议来交换消息

WSDL信息可位于

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

//ValidateEntity(“用户名”、“密码”、“公司ID”、2、键、值)


那么,如何执行此web服务并从我的php页面获得结果呢?请参见php.net中的soap调用帮助:


您需要使用PHP的SOAP库


一个简单的例子,希望对你有所帮助

$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.

正如我所说,它确实很简单,但很有效。

对于https Web服务,您需要启用openssl扩展。WS-use.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>';
$ws=new-soapclient('https://www.agemni.com/AgemniWebservices/service1.asmx?wsdl');
类验证性{
公共$strUsername,
$strPassword,
$strCompanyName,
$objecttype;
}
$parameters=新的ValidateEntity();
$parameters->strUsername='username';
$parameters->strPassword='password';
$parameters->strCompanyName='company';
$parameters->objecttype=1;
回声';
打印($ws->ValidateEntity($parameters));
回声';

检查这篇文章,它非常相似:检查其他soap调用的_getTypes()和_getFunctions(),如$ws->_调用('ValidateEntity',array('parameters'=>$parameters));用于文档/文字样式