简体   繁体   English

PHP 通过 WSDL URL 调用 Workday SOAP Webservice

[英]PHP call to Workday SOAP Webservice through WSDL URL

I am trying to call SOAP webservice for which WSDL file is already given.我正在尝试调用已为其提供 WSDL 文件的 SOAP 网络服务。 I am able to test these SOAP Request and Response through SOAP UI or Chrome Boomerang.我能够通过 SOAP UI 或 Chrome Boomerang 测试这些 SOAP 请求和响应。 I am able to get response properly.我能够得到正确的回应。

Client has shared WSDL URL, Username, and Password.客户端已共享 WSDL URL、用户名和密码。 How can I use PHP code to call services.如何使用 PHP 代码调用服务。 My concern is that I have request and response in XML format.我担心的是我有 XML 格式的请求和响应。

Can I send XML directly in the request.我可以直接在请求中发送 XML 吗? How could I make a SOAP Request with these given XML-Request information.我如何使用这些给定的 XML 请求信息发出 SOAP 请求。 Do I need to parse into objects or arrays.我是否需要解析为对象或数组。 Thanks in advance.提前致谢。

XML Request that sends me response on SOAP UI is -在 SOAP UI 上向我发送响应的 XML 请求是 -

<?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>
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();

    }

You can send the XML string with curl but I wouldn't advise to do.您可以使用 curl 发送 XML 字符串,但我不建议这样做。

My advice is to use a WSDL to PHP generator such as the PackageGenerator project.我的建议是使用 WSDL 到 PHP 生成器,例如PackageGenerator项目。 Using the generated SDK will avoid you from wondering how to construct the request.使用生成的 SDK 将避免您想知道如何构建请求。 Moreover, the response will be handled nicely and you'll end up with full OOP approach.此外,响应将得到很好的处理,您最终将获得完整的 OOP 方法。

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

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