简体   繁体   English

PHP-使用方法参数发送SOAP Web服务

[英]PHP - send SOAP web service with method parameters

I want to write a PHP code to send authentication and data to the web service. 我想编写一个PHP代码以将身份验证和数据发送到Web服务。 Please see the web service SOAP XML structure below: 请参见下面的Web服务SOAP XML结构:

This is a URL to access web API https://portal.xyzonline.com/API/ABCAPIServer.asmx?WSDL 这是访问Web API的URL 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 PHP代码

$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 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 WCFStorm的屏幕截图

I am using WCFStorm and everything is working fine. 我正在使用WCFStorm,并且一切正常。 Please see the screenshot: 请查看屏幕截图:

在此处输入图片说明

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. 如果您需要编写php脚本来发送请求,我强烈建议您使用WSDL到php生成器,例如PackageGenerator项目。 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. 您不必直接使用本机的SoapClient,SoapVar,SoapParam类,因为您只需要处理与所需参数匹配的PHP类即可。 The PHP objects you'll construct will be mapped to generate the XML request by the SoapClient class. 您将构造的PHP对象将被SoapClient类映射为生成XML请求。 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. 使用生成的软件包,您将需要具有良好的IDE(例如Eclipse PDT或PHP Storm),以了解用于自动完成的参数和值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM