首页 文章

PHP通过WSDL URL调用Workday SOAP Webservice

提问于
浏览
0

我试图调用已经给出了WSDL文件的SOAP webservice . 我可以通过SOAP UI或Chrome Boomerang测试这些SOAP请求和响应 . 我能够得到正确的回应 .

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

我可以直接在请求中发送XML . 如何使用这些给定的XML-Request信息创建SOAP请求 . 我是否需要解析对象或数组 . 提前致谢 .

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

2 回答

  • 0

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

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

  • 0
    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(). '
    '. $e->getMessage(); }

相关问题