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

PHP-使用方法参数发送SOAP web服务,php,web-services,soap,wsdl,Php,Web Services,Soap,Wsdl,我想编写一个PHP代码,将身份验证和数据发送到web服务。 请参见下面的web服务SOAP XML结构: 这是访问web API的URL 如果你能帮我写一些基本的代码,我将不胜感激 这就是我想做的: PHP代码 $client = new SoapClient("https://portal.xyzonline.com/API/ABCAPIServer.asmx?WSDL"); $params = array( 'addCaseReq' => array( 'DlcpmCase'

我想编写一个PHP代码,将身份验证和数据发送到web服务。 请参见下面的web服务SOAP XML结构:

这是访问web API的URL

如果你能帮我写一些基本的代码,我将不胜感激

这就是我想做的:

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

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

WCFStorm的屏幕截图

我正在使用WCFStorm,一切正常。请参见屏幕截图:


如果您需要编写php脚本来发送请求,我强烈建议您使用WSDL-to-php生成器,例如项目。它将真正简化要发送的数据的构造和响应的处理。您不必直接使用本机SoapClient、SoapVar、SoapParam类,因为您只需要处理与所需参数匹配的PHP类。您将构造的PHP对象将被映射到SoapClient类生成XML请求。对于生成的包,您需要有一个好的IDE,如EclipsePDT或PHP Storm,以了解用于自动完成的参数和值。

您能说明一个更具体的问题吗?你的问题中有一些代码——如果它不起作用,你能解释一下什么不起作用吗?@GrishaLevit,谢谢你的回答。我正在尝试通过身份验证将数据发送到web服务,因为您可以看到上面的屏幕截图,如果我通过了身份验证,那么我将成功发送数据,但是在上面的PHP代码中,没有提交信息。我的PHP代码似乎没有真正基于XML结构提交数据。是否安装并启用了PHP soap扩展?