National Student ClearingHouse SOAP Web服务实现

时间:2013-03-06 14:47:45

标签: php xml web-services soap-client

我正在开展一个项目,要求使用他们的API验证National Student ClearingHouse的注册会员。我一直在互联网上找到一些代码片段来描述方法或示例如何查询这个,但到目前为止没有运气。文档也非常有限,无法在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/
)

非常糟糕地坚持这一点。

1 个答案:

答案 0 :(得分:0)

错误声明为:“对象没有'BackgroundSearchPackage'属性”,基本上你的soap调用不符合wsdl的要求。我将在下面粘贴这些。此特定调用期望BOTH节点内容和属性。请参阅php文档中的第一条评论,了解如何完成:http://php.net/manual/en/soapclient.soapcall.php

因此,您可以尝试使用以下数据拨打电话:

$data = array(
    'BackgroundCheck' => array(
            '_' => array(
                'BackgroundSearchPackage' => array()
                ),
            'account' => 'xxxx',
            'userid'  => 'xxxxx',
            'password' =>  'xxxxx'
        )
);

注意:使用soap,wsdl中描述了所有可用的操作和输入描述以及返回值。您提供了网址: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>