我尝试使用PHP将提交的表单字段传递给将在我们的数据库中创建用户记录的Web服务。我知道Web服务正在运行,因为我有ColdFusion代码,能够使用本地计算机提交的参数成功创建用户帐户。但是,我需要在php中使用它,因为我们的站点是在Drupal(php)中构建的。我也尝试了wsclient(drupal模块),但无济于事。
我来到这篇文章(How to make a PHP SOAP call using the SoapClient class),这与我尝试做的很相似,但我一直收到错误。这是我正在使用的代码。另外,我需要传递安全密码才能使用它来使用它。
class Create {
function Create($securityPassword)
{
$this->securityPassword = $securityPassword;
}
}
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$create = new Create("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"); //web service password
$params = array(
"Create" => $create,
"Prefix" => "Mr",
"FirstName" => "John",
"LastName" => "Doe",
);
//print_r($params);
$response = $client->__soapCall('Create', array($params));
var_dump($response);
以下是我遇到的错误:
致命错误:未捕获的SoapFault异常:[soap:Server]服务器无法处理请求。 --->你调用的对象是空的。在C:\ wamp \ www \ sandbox \ webservice2.php:23堆栈跟踪:#0 C:\ wamp \ www \ sandbox \ webservice2.php(23):SoapClient-> __ soapCall(' Create' ,数组)在第23行的C:\ wamp \ www \ sandbox \ webservice2.php中抛出#1 {main}
我试图打电话的方法是"创建"方法。你可以看到它存在于wsdl url
中我非常感谢帮助尝试通过php使用网络服务成功创建记录。
答案 0 :(得分:0)
这应该可以让它发挥作用。
XML
<Create xmlns="http://ibridge.isgsolutions.com/Account/">
<securityPassword>string</securityPassword>
<account>
<Id>string</Id>
<Status>string</Status>
<MemberType>string</MemberType>
<JoinDate>string</JoinDate>
<Prefix>string</Prefix>
<FirstName>string</FirstName>
<MiddleName>string</MiddleName>
<LastName>string</LastName>
<Suffix>string</Suffix>
<Designation>string</Designation>
<InformalName>string</InformalName>
<MajorKey>string</MajorKey>
<Title>string</Title>
<ExcludeFromDirectory>string</ExcludeFromDirectory>
<WebSite>string</WebSite>
<Company>string</Company>
<CompanyID>string</CompanyID>
<OrgCode>string</OrgCode>
<SourceCode>string</SourceCode>
<ExcludeFromMail>string</ExcludeFromMail>
<Category>string</Category>
<Gender>string</Gender>
<BirthDate>string</BirthDate>
<WorkPhone>string</WorkPhone>
<Fax>string</Fax>
<TollFree>string</TollFree>
<HomePhone>string</HomePhone>
<Email>string</Email>
<Chapter>string</Chapter>
<FunctionalTitle>string</FunctionalTitle>
<PaidThru>string</PaidThru>
<WebLogin>string</WebLogin>
<Password>string</Password>
<SecurityGroup>string</SecurityGroup>
<ExpirationDate>string</ExpirationDate>
<StaffUser>string</StaffUser>
<WebUser>string</WebUser>
<Demographics>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
<Demographic>
<Id>string</Id>
<SequenceNumber>string</SequenceNumber>
<WindowName>string</WindowName>
<FieldName>string</FieldName>
<FieldValue>string</FieldValue>
<MultiInstance>string</MultiInstance>
</Demographic>
</Demographics>
</account>
</Create>
码
$client = new SoapClient("https://isgweb.entnet.org/iservices/Account.asmx?WSDL");
$params = [
"Create" => [
'securityPassword' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'account' => [
'Prefix' => 'Mr',
'FirstName' => 'John',
'LastName' => 'Doe'
]
]
];
$response = $client->__soapCall('Create', $params)->CreateResult;
var_dump($response);