我正在做一个项目,其中需要使用National Student ClearingHouse的API验证注册成员。我一直在寻找到处在互联网上找到一些片段描述的方法或例子如何查询这个,但没有运气到目前为止。在php中实现的文档也非常有限,而且我从来没有使用过SOAP,所以这对我来说更加复杂。
文档链接:https://docs.google.com/file/d/1kZvEeobFNq3kbhZKJnagkVhcWhKHHwL5dwckbJLTB4dhNpMSF7cjAVOp9cne/edit?usp=sharing
不知怎么的,我已经开始了这里是代码:
$soap_url = 'https://xml.studentclearinghouse.org/ws/wsdl/HRXMLVerify.wsdl';
$client = new SoapClient($soap_url, array(
'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
'SOAPENC' => 'http://schemas.xmlsoap.org/soap/encoding/',
'xsi' => 'http://www.w3.org/2001/XMLSchemainstance',
'xsd' => 'http://www.w3.org/2001/XMLSchema'
));
$data = array(
'BackgroundCheck' => array(
'account' => 'xxxx',
'userid' => 'xxxxx',
'password' => 'xxxxx'
),
'BackgroundSearchPackage' => array()
);
echo '<pre>';
print_r($client->__soapCall('verifyHRXML', $data));
输出:
SoapFault Object
(
[message:protected] => SOAP-ERROR: Encoding: object has no 'BackgroundSearchPackage' property
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /Applications/MAMP/htdocs/nch/index.php
[line:protected] => 39
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /Applications/MAMP/htdocs/nch/index.php
[line] => 39
[function] => __soapCall
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => verifyHRXML
[1] => Array
(
[BackgroundCheck] => Array
(
[account] => xxxxxx
[userid] => xxxxx
[password] => xxxxxx
)
[BackgroundSearchPackage] => Array
(
)
)
)
)
)
[previous:Exception:private] =>
[faultstring] => SOAP-ERROR: Encoding: object has no 'BackgroundSearchPackage' property
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)
我很纠结。
错误说明为:"对象没有'BackgroundSearchPackage'属性",基本上您的soap调用不遵守wsdl的要求。我把这些粘贴在下面。这个特定的调用需要节点内容和属性。查看php文档中的第一条注释,了解如何完成:http://php.net/manual/en/soapclient.soapcall.php
所以说,你可以试着用你的数据拨打电话:
$data = array(
'BackgroundCheck' => array(
'_' => array(
'BackgroundSearchPackage' => array()
),
'account' => 'xxxx',
'userid' => 'xxxxx',
'password' => 'xxxxx'
)
);
注意:使用soap,所有可用的操作及其输入和返回值的描述都在wsdl中描述。您提供了url: https://xml.studentclearinghouse.org/ws/wsdl/HRXMLVerify.wsdl。我把你的案例的相关信息贴在下面:
<message name="HRXMLVerifySoapIn">
<part name="parameters" element="s0:BackgroundCheck"/>
</message>
<message name="HRXMLVerifySoapOut">
<part name="parameters" element="s0:BackgroundReports"/>
</message>
<portType name="HRXMLVerifySoapPort">
<operation name="verifyHRXML">
<documentation>Display the detail results of verification.</documentation>
<input message="intf:HRXMLVerifySoapIn"/>
<output message="intf:HRXMLVerifySoapOut"/>
</operation>
</portType>
BackgroundCheck说明
<xsd:element name="BackgroundCheck" type="BackgroundCheckType" >
<xsd:annotation>
<xsd:documentation>Parent Element for specifying Search Subject specfic data for Standalone Searches.</xsd:documentation>
</xsd:annotation>
</xsd:element>
BackgroundCheckType的描述(参见wsdl的3195行)。BackgroundCheckType 包含一个元素"BackgroundSearchPackage"。
<xsd:complexType name="BackgroundCheckType" >
<xsd:sequence>
<xsd:element name="ReferenceId" type="EntityIdType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Reference Number associated with all searches within the XML Document.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="BackgroundSearchPackage" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Root element containing all screening related information for a single Search Subject.</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:sequence>
<xsd:element name="ReferenceId" type="EntityIdType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Reference Number associated with all searches within the specified package.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="ClientContact" type="ReferralType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Contact point within clients organization regarding details of screening package.< /xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="Organization" type="ReferralType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Identifies the organization that the search(s) will be performed upon or on behalf of depending on the value of type.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="PersonalData" type="ScreeningPersonalDataType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>Personal data related to the Search Subject that the search(s) will be performed upon.</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="Screenings" type="ScreeningRequestType" minOccurs="0" maxOccurs="unbounded"></xsd:element>
</xsd:sequence>
</xsd:sequence>
<xsd:attribute name="type" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="action" type="xsd:string" use="optional"></xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element ref="UserArea" minOccurs="0"></xsd:element>
</xsd:sequence>
<xsd:attribute name="userId" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>Client identification. This will be provided to the client by the organization performing the screenings.</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="password" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="account" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="location" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="version" type="xsd:string" use="optional" default="2_0"></xsd:attribute>
<xsd:attribute ref="xml:lang" use="optional"></xsd:attribute>
</xsd:complexType>