PHP 通过 WSDL 调用 Workday SOAP Webservice URL

PHP call to Workday SOAP Webservice through WSDL URL

我正在尝试调用已提供 WSDL 文件的 SOAP 网络服务。我能够通过 SOAP UI 或 Chrome Boomerang 测试这些 SOAP 请求和响应。我能够正确地得到响应。

客户端已共享 WSDL URL、用户名和密码。 如何使用 PHP 代码调用服务。我担心的是我有 XML 格式的请求和响应。

我可以在请求中直接发送 XML 吗?我如何使用这些给定的 XML-Request 信息发出 SOAP 请求。我需要解析成对象还是数组。提前致谢。

XML 在 SOAP UI 上向我发送响应的请求是 -

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <env:Header>
        <xsd:sample_Common_Header>
            <xsd:Include_Reference_Descriptors_In_Response>false</xsd:Include_Reference_Descriptors_In_Response>
        </xsd:sample_Common_Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:UsernameToken>
                <wsse:Username>Assessment@tenant</wsse:Username>
                <wsse:Password>Test@1234</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </env:Header>
    <env:Body>
        <wd:Get_Assess_Candidate_Request
            xmlns:wd="urn:com.sample/bsvc"
            wd:version="v29.0">
              <wd:Request_Criteria>
<wd:Candidate_Criteria_Data>
<wd:Candidate_Reference>
<wd:ID wd:type="Candidate_ID">C0000417</wd:ID>
</wd:Candidate_Reference>
</wd:Candidate_Criteria_Data>
 </wd:Request_Criteria>
 <wd:Response_Filter>
                <wd:As_Of_Effective_Date>2018-01-16</wd:As_Of_Effective_Date>
                <wd:As_Of_Entry_DateTime>2018-01-16T11:17:34</wd:As_Of_Entry_DateTime>
                <wd:Page>1</wd:Page>
                <wd:Count>100</wd:Count>
            </wd:Response_Filter>
        </wd:Get_Assess_Candidate_Request>
    </env:Body>
</env:Envelope>

您可以使用 curl 发送 XML 字符串,但我不建议这样做。

我的建议是使用 WSDL 到 PHP 生成器,例如 PackageGenerator 项目。使用生成的 SDK 将避免您想知道如何构造请求。此外,响应将得到很好的处理,您最终将获得完整的 OOP 方法。

function AddWSSUsernameToken($client, $username, $password)
{
    $wssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

    $username = new SoapVar($username, 
                            XSD_STRING, 
                            null, null, 
                            'Username', 
                            $wssNamespace);

    $password = new SoapVar($password, 
                            XSD_STRING, 
                            null, null, 
                            'Password', 
                            $wssNamespace);

    $usernameToken = new SoapVar(array($username, $password), 
                                    SOAP_ENC_OBJECT, 
                                    null, null, 'UsernameToken', 
                                    $wssNamespace);

    $usernameToken = new SoapVar(array($usernameToken), 
                            SOAP_ENC_OBJECT, 
                            null, null, null, 
                            $wssNamespace);

    $wssUsernameTokenHeader = new SoapHeader($wssNamespace, 'Security', $usernameToken);

    $client->__setSoapHeaders($wssUsernameTokenHeader);
}

function get_soap_client(){


    $username = 'Assessment@tenant';
    $password = 'Test@1234';
    $wsdl = 'https://wd5-impl-
    services1.workday.com/ccx/service/tenant/Recruiting/v29.1?wsdl';

    $options = array(
            'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
            'style'=>SOAP_RPC,
            'use'=>SOAP_ENCODED,
            'soap_version'=>SOAP_1_1,
            'cache_wsdl'=>WSDL_CACHE_NONE,
            'connection_timeout'=>15,
            'trace'=>true,
            'encoding'=>'UTF-8',
            'exceptions'=>true,
    );


    $client = new SoapClient($wsdl, $options);
    AddWSSUsernameToken($client, $username, $password);

    return $client;    

}


try
    {

        $params = array(); //define your parameters here
        $client = get_soap_client();
        $response = $client->__soapCall('method-name',$params);

    }
    catch(Exception $e){ 
        echo $e->getCode(). '<br />'. $e->getMessage();

    }