微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 C++ 中使用 Windows Web 服务 API 编码 UPS Web 服务时出现问题

如何解决在 C++ 中使用 Windows Web 服务 API 编码 UPS Web 服务时出现问题

我有一个 C++ 应用程序,我正在尝试使用它通过 Windows Web 服务 API 联系 UPS Web 服务。 UPS提供了一些C#的编程例子,我把最简单的例子(LabelRecovery——从web服务中读取标签)翻译成了c++。

C# 程序在下载后正常运行。运行我翻译的c++版本时,遇到错误

Failure: errorCode=0x803d0000
There was an error communicating with the endpoint at 'https://wwwcie.ups.com/webservices/LBRecovery'.
The content type 'text/xml' did not match the expected value 'application/soap+xml'.

也许我缺少一个内容类型设置,我尝试根据其他研究过的文章修改各种 CHANNEL 和 PROXY 设置,但没有成功。因此,如果您仅从上面的描述中知道我遗漏了什么,那么您可以停止阅读此处并请告诉我如何继续。

我不确定的程序的一个方面是尝试附加消息的 UPSSecurity 部分,该部分通知 UPS 用户/密码......我从不主动将 UPSSecurity 结构链接到消息,但它可能是隐式链接,我只是没有看到它。

Windows Web 服务 (WWS) 使用名为“wsutil.exe”的程序将 UPS(wsdl、xsd...)提供的 Web 服务描述文件转换为绑定,WWS API 将使用这些绑定来创建消息交流。 LabelRecovery 定义文件 (wsdl) 使用以下部分来描述 LabelRecoveryRequest 消息:

  <wsdl:message name="LabelRecoveryRequestMessage">
    <wsdl:part name="Body" element="lbrec:LabelRecoveryRequest" />
    <wsdl:part name="UPSSecurity" element="upss:UPSSecurity" />
  </wsdl:message>

这个定义使它看起来像“UPSSecurity”是标签恢复请求消息的一部分。但是我找不到可用于链接我的 UPSSecurity 信息的可寻址参考。 wsutil.exe 实用程序生成的“c”代码仅在注释中引用“UPSSecurity”:

// Fault Message LabelRecoveryWS_wsdl.faults.LabelRecoveryWS_wsdl_LabelRecoveryErrorMessage,// Fault Action 
    // fault message Error1_1_xsd_Errors
//  input message soap header element is
//(WS_ELEMENT_DESCRIPTION*)&UPSSecurity_xsd.globalElements.UPSSecurity_xsd_UPSSecurity,//input message soap headerfault element is
//(WS_ELEMENT_DESCRIPTION*)&Error1_1_xsd.globalElements.Error1_1_xsd_Errors,// operation: LabelRecoveryWS_wsdl_LabelRecoveryBinding_ProcessLabelRecovery
HRESULT WINAPI LabelRecoveryWS_wsdl_LabelRecoveryBinding_ProcessLabelRecovery(
    _In_ WS_SERVICE_PROXY* _serviceProxy,_In_ _LBRecovery_xsd_LabelRecoveryRequest* LabelRecoveryWS_wsdl_Body,_Outptr_ _LBRecovery_xsd_LabelRecoveryResponse** outLabelRecoveryWS_wsdl_Body,_In_ WS_HEAP* _heap,_In_reads_opt_(_callPropertyCount) const WS_CALL_PROPERTY* _callProperties,_In_ const ULONG _callPropertyCount,_In_opt_ const WS_ASYNC_CONTEXT* _asyncContext,_In_opt_ WS_ERROR* _error)
{
    void* _argList[2]; 
    _argList[0] = &LabelRecoveryWS_wsdl_Body;
    _argList[1] = &outLabelRecoveryWS_wsdl_Body;
    return WsCall(_serviceProxy,(WS_OPERATION_DESCRIPTION*)&LabelRecoveryWS_wsdlLocalDeFinitions.contracts.LabelRecoveryWS_wsdl_LabelRecoveryBinding.LabelRecoveryWS_wsdl_LabelRecoveryBinding_ProcessLabelRecovery.LabelRecoveryWS_wsdl_LabelRecoveryBinding_ProcessLabelRecovery,(const void **)&_argList,_heap,_callProperties,_callPropertyCount,_asyncContext,_error);
}

具体来说,//(WS_ELEMENT_DESCRIPTION*)&UPSSecurity_xsd.globalElements.UPSSecurity_xsd_UPSSecurity,。该评论似乎推断这应该作为 SOAP 标头放置,而不是作为 LabelRecoveryRequest 消息的一部分,但我无法就如何处理我的 UPSSecurity 结构、SOAP 标头或其他方式建立联系。我希望你们中的一位聪明人以前遇到过这个问题,并能得到完美的回应。

提供整套代码会很冗长,所以我希望我的摘录显示足够的细节,至少可以开始讨论。如果有帮助的话,我是根据 Windows Web 服务 API 的“服务模型”编写的。

预先感谢您的帮助。

(我在 Visual Studio 17 中构建它,并在具有最新更新的 Windows 10 21H1 上运行。)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。