2

我正在使用SOAP包通过 xml 向 workday-api 发出请求。

问题在于肥皂包生成的 xml。

生成的 XML

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:wd-wsdl="urn:com.workday/bsvc/Recruiting"
    xmlns:wd="urn:com.workday/bsvc"
    xmlns:nyw="urn:com.netyourwork/aod">
    <soapenv:Header>
        <wsse:Security soapenv:mustUnderstand="1"
            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>Username</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <wd:Get_Applicants_Request
            xmlns:wd="urn:com.workday/bsvc"
            xmlns="urn:com.workday/bsvc">
            <bsvc:Get_Applicants_Request bsvc:version="v32.1">
                <bsvc:Request_Criteria>
                    <bsvc:Email_Address>abc@gmail.com</bsvc:Email_Address>
                </bsvc:Request_Criteria>
                <bsvc:Response_Group>
                    <bsvc:Include_Reference>true</bsvc:Include_Reference>
                    <bsvc:Include_Personal_Information>true</bsvc:Include_Personal_Information>
                    <bsvc:Include_Recruiting_Information>true</bsvc:Include_Recruiting_Information>
                    <bsvc:Include_Qualification_Profile>true</bsvc:Include_Qualification_Profile>
                    <bsvc:Include_Resume>false</bsvc:Include_Resume>
                    <bsvc:Include_Background_Check>false</bsvc:Include_Background_Check>
                    <bsvc:Include_External_Integration_ID_Data>false</bsvc:Include_External_Integration_ID_Data>
                </bsvc:Response_Group>
            </bsvc:Get_Applicants_Request>
        </wd:Get_Applicants_Request>
    </soapenv:Body>
</soapenv:Envelope>

我需要xml如下

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:bsvc="urn:com.workday/bsvc">
    <soapenv:Header>
        <wsse:Security soapenv:mustUnderstand="1"
            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>Username</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <bsvc:Get_Applicants_Request bsvc:version="v32.1">
            <bsvc:Request_Criteria>
                <bsvc:Email_Address>abc@gmail.com</bsvc:Email_Address>
            </bsvc:Request_Criteria>
            <bsvc:Response_Group>
                <bsvc:Include_Reference>true</bsvc:Include_Reference>
                <bsvc:Include_Personal_Information>true</bsvc:Include_Personal_Information>
                <bsvc:Include_Recruiting_Information>true</bsvc:Include_Recruiting_Information>
                <bsvc:Include_Qualification_Profile>true</bsvc:Include_Qualification_Profile>
                <bsvc:Include_Resume>false</bsvc:Include_Resume>
                <bsvc:Include_Background_Check>false</bsvc:Include_Background_Check>
                <bsvc:Include_External_Integration_ID_Data>false</bsvc:Include_External_Integration_ID_Data>
            </bsvc:Response_Group>
        </bsvc:Get_Applicants_Request>
    </soapenv:Body>
</soapenv:Envelope>

soapenv:envelope生成的 xml 中包含额外的命名空间。如何删除它。在soapenv:body标签之后我得到了额外的标签。

我在下面传递标题和正文的详细信息。

标题:

let soapHeader = `<wsse:Security soapenv:mustUnderstand="1"
    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>Username</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
    </wsse:UsernameToken>
</wsse:Security>`

与身体:

let xml = `<bsvc:Get_Applicants_Request bsvc:version="v32.1">
    <bsvc:Request_Criteria>
        <bsvc:Email_Address>abc@gmail.com</bsvc:Email_Address>
    </bsvc:Request_Criteria>
    <bsvc:Response_Group>
        <bsvc:Include_Reference>true</bsvc:Include_Reference>
        <bsvc:Include_Personal_Information>true</bsvc:Include_Personal_Information>
        <bsvc:Include_Recruiting_Information>true</bsvc:Include_Recruiting_Information>
        <bsvc:Include_Qualification_Profile>true</bsvc:Include_Qualification_Profile>
        <bsvc:Include_Resume>false</bsvc:Include_Resume>
        <bsvc:Include_Background_Check>false</bsvc:Include_Background_Check>
        <bsvc:Include_External_Integration_ID_Data>false</bsvc:Include_External_Integration_ID_Data>
    </bsvc:Response_Group>
</bsvc:Get_Applicants_Request>`

并使用以下方法使用soap请求xml,因为工作日提供soap api。

let client = await soap.createClientAsync(url, wsdlOptions)
client.addSoapHeader(soapHeader)
let resp = await client.Get_ApplicantsAsync(xml)

请帮助我根据需要使用 SOAP 包制作 xml。

4

1 回答 1

1

您提供的代码示例未显示您作为方法参数提供的内容(代码中的 xml 对象是什么?)。

根据帖子,我假设您正在自己构建 xml 字符串并希望将其直接传递给 SOAP 包。在这种情况下,您的方法参数应该看起来像(“Example with XML String for the args” in the package docs)

const resp = await client.Get_ApplicantsAsync({_xml: xmlBody})

请记住,您缺少bsvc名称空间。
您可以直接在您的 xml 正文中将其添加到Get_Applicants_Request元素中:

<bsvc:Get_Applicants_Request xmlns:bsvc="urn:com.workday/bsvc" bsvc:version="v32.1">
</bsvc:Get_Applicants_Request>

或者您可以将其包含在信封中(也许您还有其他调用也需要此命名空间):

client.wsdl.xmlnsInEnvelope += 'xmlns:bsvc="urn:com.workday/bsvc';
于 2019-06-13T08:07:56.087 回答