gpt4 book ai didi

node.js - 如何更改node.js中soap包生成的xml?

转载 作者:太空宇宙 更新时间:2023-11-04 01:29:21 35 4
gpt4 key购买 nike

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

问题出在由soap包生成的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>

在soap生成的xml中,在soapenv:envelope中包含额外的命名空间。如何去除它。我在 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,因为workday提供soap api。

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

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

最佳答案

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

根据这篇文章,我假设您正在自己构建 xml 字符串并希望将其直接传递到 SOAP 包。在这种情况下,您的方法参数应类似于(包文档中的“参数的 XML 字符串示例”)

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';

关于node.js - 如何更改node.js中soap包生成的xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56575007/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com