0

I want to write a PHP code to send authentication and data to the web service. Please see the web service SOAP XML structure below:

This is a URL to access web API https://portal.xyzonline.com/API/ABCAPIServer.asmx?WSDL

I will really appreciate if you can help me to just write basic code.

This is what I am trying to do:

PHP Code

$client = new SoapClient("https://portal.xyzonline.com/API/ABCAPIServer.asmx?WSDL");
$params = array(
'addCaseReq' => array(
    'DlcpmCase' => array(
        'CaseID' => '1234',
        'CustomerID' => '222',
        'PatientFirst' => 'John'
        ),
     'Auth' => array(
        'AppName' => 'appname',
        'UserName' => 'username',
        'Password' => 'password'
        )
     )
   );
try { 
    $responsetest = $client->AddCase(new SoapParam(array($params)));
} catch(SoapFault $fault) { 
    print_r($fault); 
}

XML

<wsdl:types>
 <s:schema>
  <s:element name="AddCase">
   <s:complexType>
    <s:sequence>
     <s:element minOccurs="0" maxOccurs="1" name="addCaseReq" type="tns:ABCAPIAddCaseRequest"/>
    </s:sequence>
   </s:complexType>
  </s:element>
  <s:complexType name="ABCAPIAddCaseRequest">
   <s:complexContent mixed="false">
    <s:extension base="tns:ABCAPIRequest">
     <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="AbcCase" type="tns:ABCCase"/>
     </s:sequence>
    </s:extension>
   </s:complexContent>
  </s:complexType>
  <s:complexType name="ABCAPIRequest" abstract="true">
   <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="Auth" type="tns:ABCAPIAuthentication"/>
   </s:sequence>
  </s:complexType>
  <s:complexType name="ABCAPIAuthentication">
   <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="AppName" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
   </s:sequence>
  </s:complexType>
  <s:complexType name="ABCCase">
   <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="CaseID" type="s:string"/>
    <s:element minOccurs="1" maxOccurs="1" name="CaseNumber" type="s:int"/>
    <s:element minOccurs="0" maxOccurs="1" name="CustomerID" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="PatientFirst" type="s:string"/>
   </s:sequence>
  </s:complexType>
 </s:schema>
</wsdl:types>

Screenshot of WCFStorm

I am using WCFStorm and everything is working fine. Please see the screenshot:

enter image description here

3
  • Can you state a more specific problem? You have some code in your question -- if it's not working, can you explain what's not working about it? Commented Jan 15, 2017 at 0:31
  • @GrishaLevit, thank you for your response. I am trying to send data to web service with the authentication as you can see the screenshot above that I am sending the data successfully if i pass the authentications and the data but in my PHP code above, doesn't submit the information. it seems like my PHP code doesn't really submitting the data based on the XML structure Commented Jan 15, 2017 at 0:45
  • 1
    Did the php soap extension be installed and enabled? stackoverflow.com/questions/22594582/… Commented Jan 15, 2017 at 4:46

1 Answer 1

1

If you need to write a php script to send the request, I would strongly advise you to use a WSDL to php generator such as the PackageGenerator project. It will really ease you the construction of the data to send and the handling of the response. You won't have to use directly the native SoapClient, SoapVar, SoapParam classes as you'll only deal with PHP classes that match the required parameters. The PHP objects you'll construct will be mapped to generate the XML request by the SoapClient class. With the generated package, you'll then need to have a good IDE such as Eclipse PDT or PHP Storm to know the parameters and values to use with the auto completion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.