0

I'm trying to use PHP to pass submitted form fields to a web service that will create a user record in our database. I know the web service is working because I have ColdFusion code that is able to successfully create a user account with submitted parameters from my local machine. However, I need to get this working in php since our site is built in Drupal (php). I also tried the wsclient (drupal module) but to no avail.

I came accross this post (How to make a PHP SOAP call using the SoapClient class) which is similar to what I'm trying to do, but I keep getting an error. Here is the code I'm working with. Also, I need to pass the security password to use the web service in order to use it.

  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);

Here is the error I'm getting:

Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\wamp\www\sandbox\webservice2.php:23 Stack trace: #0 C:\wamp\www\sandbox\webservice2.php(23): SoapClient->__soapCall('Create', Array) #1 {main} thrown in C:\wamp\www\sandbox\webservice2.php on line 23

The method I'm trying to call is the "Create" method. You can see it exists in the wsdl url

I'd appreciate help in trying to successfully create a record using the web service via php.

Community
  • 1
  • 1
pya26
  • 3
  • 1

1 Answers1

0

This should allow it work.

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>

code

$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);
Jonathan
  • 2,778
  • 13
  • 23
  • hope you have just as much with soap requests as I did :) – Jonathan May 07 '15 at 16:36
  • I have a follow up question. How would I convert this to work in Drupal? I thought I would be able to plug this code directly into a function within Drupal, but it throws an error because of the brackets, and may also throw an error because of the SoapClient. – pya26 May 07 '15 at 20:06
  • This should just work. What is the error that you are specifically getting? – Jonathan May 07 '15 at 20:09
  • I figured it out. That array syntax was introduced in PHP 5.4, and my Drupal environment is running 5.3.29. I tried the old style array syntax "array()" vs "[]" and it worked. Thank you. – pya26 May 07 '15 at 20:47