Delphi 2007 WSDL导入,设置SOAP头信息

发布于 2024-08-02 08:16:43 字数 7044 浏览 6 评论 0原文

在 Delphi 2007 中导入 WDSL 工作正常,但会生成“无法展开”警告(下面​​的代码片段 1 [就像 StackOverFlow 上已经记录的另一个问题])。

但是,从生成的代码中尚不清楚我们如何设置标头 (REQUESTOR:pIn, REQUEST_USER:pIn, REQUEST_PASSWORD:pIn)。在网络上的其他地方,我们还尝试了命令行实用程序 WDSLImp,它允许我们使用开关,例如,解开文字。不好。

片段 2 显示了初始化内容,我们尝试用实际值替换三个标头参数。最终结果应该出现在界面上,如代码片段 3 所示。

非常感谢所有帮助。

片段 1:

// ************************************************************************ //
// Namespace : http//www.sx3.com/GET_SERVICE_STATUS.wsdl
// soapAction: https//xxx.org.uk:23105/communication/gateway
// transport : http//schemas.xmlsoap.org/soap/http
// style     : document
// binding   : UpdGetServiceStatusBinding
// service   : UpdGetServiceStatusService
// port      : UpdGetServiceStatusPort
// URL       : http//machine:port/communication/UpdGetServiceStatus
// ************************************************************************ //
UpdGetServiceStatusPort = interface(IInvokable)
['{CB3F81D1-5267-4897-C244-288E348AA34E}']

// Cannot unwrap: 
//     - Input element wrapper name does not match operation's name
//     - More than one strictly out element was found
// Headers: REQUESTOR:pIn, REQUEST_USER:pIn, REQUEST_PASSWORD:pIn
function  UpdGetServiceStatus(const parameters: GetServiceStatusRequest): GET_SERVICE_STATUS; stdcall;
end;

function GetUpdGetServiceStatusPort(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): UpdGetServiceStatusPort;


implementation
  uses SysUtils;

function GetUpdGetServiceStatusPort(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): UpdGetServiceStatusPort;
const
  defWSDL = 'get_service_status_net.wsdl';
  defURL  = 'http//machine:port/communication/UpdGetServiceStatus';
  defSvc  = 'UpdGetServiceStatusService';
  defPrt  = 'UpdGetServiceStatusPort';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as UpdGetServiceStatusPort);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;

片段 2:

initialization
  InvRegistry.RegisterInterface(TypeInfo(UpdGetServiceStatusPort), 'http//www.sx3.com/GET_SERVICE_STATUS.wsdl', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(UpdGetServiceStatusPort), 'https//xxx.org.uk:23105/communication/gateway');
  InvRegistry.RegisterInvokeOptions(TypeInfo(UpdGetServiceStatusPort), ioDocument);
  InvRegistry.RegisterInvokeOptions(TypeInfo(UpdGetServiceStatusPort), ioLiteral);
  InvRegistry.RegisterHeaderClass(TypeInfo(UpdGetServiceStatusPort), REQUESTOR, 'REQUESTOR', 'http//www.yyy.com/IntegratorCoreTypes');
  InvRegistry.RegisterHeaderClass(TypeInfo(UpdGetServiceStatusPort), REQUEST_USER, 'REQUEST_USER', 'http//www.yyy.com/IntegratorCoreTypes');
  InvRegistry.RegisterHeaderClass(TypeInfo(UpdGetServiceStatusPort), REQUEST_PASSWORD, 'REQUEST_PASSWORD', 'http//www.yyy.com/IntegratorCoreTypes');
  InvRegistry.RegisterExternalParamName(TypeInfo(UpdGetServiceStatusPort), 'UpdGetServiceStatus', 'parameters1', 'parameters');
  RemClassRegistry.RegisterXSInfo(TypeInfo(APIMessagesType), 'http//www.sx3.com/UpdGetServiceStatusResponse', 'APIMessagesType');
  RemClassRegistry.RegisterXSClass(GET_SERVICE_STATUS, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'GET_SERVICE_STATUS');
  RemClassRegistry.RegisterSerializeOptions(GET_SERVICE_STATUS, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(GetServiceStatusRequestType, 'http//www.sx3.com/GET_SERVICE_STATUS', 'GetServiceStatusRequestType');
  RemClassRegistry.RegisterSerializeOptions(GetServiceStatusRequestType, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(GetServiceStatusRequest, 'http//www.sx3.com/GET_SERVICE_STATUS', 'GetServiceStatusRequest');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char4000), 'http://www.sx3.com/houCommonTypes', 'char4000');
  RemClassRegistry.RegisterXSClass(GetServiceStatusType, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'GetServiceStatusType');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char25), 'http//www.sx3.com/houCommonTypes', 'char25');
  RemClassRegistry.RegisterXSClass(APIMessageType, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'APIMessageType');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char30), 'http//www.sx3.com/houCommonTypes', 'char30');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char7), 'http//www.sx3.com/houCommonTypes', 'char7');
  RemClassRegistry.RegisterXSClass(MESSAGEType, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGEType');
  RemClassRegistry.RegisterExternalPropName(TypeInfo(MESSAGEType), 'TYPE_', 'TYPE');
  RemClassRegistry.RegisterXSInfo(TypeInfo(int15), 'http//www.sx3.com/houCommonTypes', 'int15');
  RemClassRegistry.RegisterXSClass(GetServiceStatusResponseType, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'GetServiceStatusResponseType');
  RemClassRegistry.RegisterXSInfo(TypeInfo(RETURNED_MESSAGESType), 'http//www.sx3.com/sx3returnedmessages', 'RETURNED_MESSAGESType');
  RemClassRegistry.RegisterXSClass(MESSAGE_RETURN_INFO, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGE_RETURN_INFO');
  RemClassRegistry.RegisterXSClass(MESSAGE_RETURN_INFO2, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGE_RETURN_INFO2', 'MESSAGE_RETURN_INFO');
  RemClassRegistry.RegisterXSClass(REQUESTOR, 'http//www.yyy.com/IntegratorCoreTypes', 'REQUESTOR');
  RemClassRegistry.RegisterSerializeOptions(REQUESTOR, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(REQUEST_USER, 'http//www.yyy.com/IntegratorCoreTypes', 'REQUEST_USER');
  RemClassRegistry.RegisterSerializeOptions(REQUEST_USER, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(REQUEST_PASSWORD, 'http//www.yyy.com/IntegratorCoreTypes', 'REQUEST_PASSWORD');
  RemClassRegistry.RegisterSerializeOptions(REQUEST_PASSWORD, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(APIMessage, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'APIMessage');
  RemClassRegistry.RegisterXSClass(MESSAGE_, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGE_', 'MESSAGE');

片段 3:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http//schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance" 
xmlns:xs="http//www.w3.org/2001/XMLSchema" 
xmlns:ig="http//www.yyy.com/IntegratorCoreTypes" 
xmlns:ng1="http//www.sx3.com/GET_WORKS_ORDERS_LIST">
  <soap:Header>
    <ig:REQUESTOR>REALREQUESTOR</ig:REQUESTOR>
    <ig:REQUEST_USER>REALREQUEST_USER</ig:REQUEST_USER>
    <ig:REQUEST_PASSWORD>realpassword</ig:REQUEST_PASSWORD>
  </soap:Header>
  <soap:Body>
    <ng1:WorksOrdersListRequest/>
  </soap:Body>
</soap:Envelope>

Importing WDSL in Delphi 2007 works fine, but generates a Cannot Unwrap warning (code snippet 1, below [like another question already logged on StackOverFlow]).

However, it is how we set the headers (REQUESTOR:pIn, REQUEST_USER:pIn, REQUEST_PASSWORD:pIn) that is unclear from the generated code. Looking elsewhere on the Net, we also tried the command line utilitiy WDSLImp, which allowed us to use switches to, for example, unwrap literals. No good.

Snippet 2 shows the initialization stuff, which we have variously tried substituting real values for the three header parameters. The end result should appear over the interface like this snippet 3.

All help very much appreciated.

Snippet 1:

// ************************************************************************ //
// Namespace : http//www.sx3.com/GET_SERVICE_STATUS.wsdl
// soapAction: https//xxx.org.uk:23105/communication/gateway
// transport : http//schemas.xmlsoap.org/soap/http
// style     : document
// binding   : UpdGetServiceStatusBinding
// service   : UpdGetServiceStatusService
// port      : UpdGetServiceStatusPort
// URL       : http//machine:port/communication/UpdGetServiceStatus
// ************************************************************************ //
UpdGetServiceStatusPort = interface(IInvokable)
['{CB3F81D1-5267-4897-C244-288E348AA34E}']

// Cannot unwrap: 
//     - Input element wrapper name does not match operation's name
//     - More than one strictly out element was found
// Headers: REQUESTOR:pIn, REQUEST_USER:pIn, REQUEST_PASSWORD:pIn
function  UpdGetServiceStatus(const parameters: GetServiceStatusRequest): GET_SERVICE_STATUS; stdcall;
end;

function GetUpdGetServiceStatusPort(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): UpdGetServiceStatusPort;


implementation
  uses SysUtils;

function GetUpdGetServiceStatusPort(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): UpdGetServiceStatusPort;
const
  defWSDL = 'get_service_status_net.wsdl';
  defURL  = 'http//machine:port/communication/UpdGetServiceStatus';
  defSvc  = 'UpdGetServiceStatusService';
  defPrt  = 'UpdGetServiceStatusPort';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as UpdGetServiceStatusPort);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;

Snippet 2:

initialization
  InvRegistry.RegisterInterface(TypeInfo(UpdGetServiceStatusPort), 'http//www.sx3.com/GET_SERVICE_STATUS.wsdl', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(UpdGetServiceStatusPort), 'https//xxx.org.uk:23105/communication/gateway');
  InvRegistry.RegisterInvokeOptions(TypeInfo(UpdGetServiceStatusPort), ioDocument);
  InvRegistry.RegisterInvokeOptions(TypeInfo(UpdGetServiceStatusPort), ioLiteral);
  InvRegistry.RegisterHeaderClass(TypeInfo(UpdGetServiceStatusPort), REQUESTOR, 'REQUESTOR', 'http//www.yyy.com/IntegratorCoreTypes');
  InvRegistry.RegisterHeaderClass(TypeInfo(UpdGetServiceStatusPort), REQUEST_USER, 'REQUEST_USER', 'http//www.yyy.com/IntegratorCoreTypes');
  InvRegistry.RegisterHeaderClass(TypeInfo(UpdGetServiceStatusPort), REQUEST_PASSWORD, 'REQUEST_PASSWORD', 'http//www.yyy.com/IntegratorCoreTypes');
  InvRegistry.RegisterExternalParamName(TypeInfo(UpdGetServiceStatusPort), 'UpdGetServiceStatus', 'parameters1', 'parameters');
  RemClassRegistry.RegisterXSInfo(TypeInfo(APIMessagesType), 'http//www.sx3.com/UpdGetServiceStatusResponse', 'APIMessagesType');
  RemClassRegistry.RegisterXSClass(GET_SERVICE_STATUS, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'GET_SERVICE_STATUS');
  RemClassRegistry.RegisterSerializeOptions(GET_SERVICE_STATUS, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(GetServiceStatusRequestType, 'http//www.sx3.com/GET_SERVICE_STATUS', 'GetServiceStatusRequestType');
  RemClassRegistry.RegisterSerializeOptions(GetServiceStatusRequestType, [xoLiteralParam]);
  RemClassRegistry.RegisterXSClass(GetServiceStatusRequest, 'http//www.sx3.com/GET_SERVICE_STATUS', 'GetServiceStatusRequest');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char4000), 'http://www.sx3.com/houCommonTypes', 'char4000');
  RemClassRegistry.RegisterXSClass(GetServiceStatusType, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'GetServiceStatusType');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char25), 'http//www.sx3.com/houCommonTypes', 'char25');
  RemClassRegistry.RegisterXSClass(APIMessageType, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'APIMessageType');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char30), 'http//www.sx3.com/houCommonTypes', 'char30');
  RemClassRegistry.RegisterXSInfo(TypeInfo(char7), 'http//www.sx3.com/houCommonTypes', 'char7');
  RemClassRegistry.RegisterXSClass(MESSAGEType, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGEType');
  RemClassRegistry.RegisterExternalPropName(TypeInfo(MESSAGEType), 'TYPE_', 'TYPE');
  RemClassRegistry.RegisterXSInfo(TypeInfo(int15), 'http//www.sx3.com/houCommonTypes', 'int15');
  RemClassRegistry.RegisterXSClass(GetServiceStatusResponseType, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'GetServiceStatusResponseType');
  RemClassRegistry.RegisterXSInfo(TypeInfo(RETURNED_MESSAGESType), 'http//www.sx3.com/sx3returnedmessages', 'RETURNED_MESSAGESType');
  RemClassRegistry.RegisterXSClass(MESSAGE_RETURN_INFO, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGE_RETURN_INFO');
  RemClassRegistry.RegisterXSClass(MESSAGE_RETURN_INFO2, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGE_RETURN_INFO2', 'MESSAGE_RETURN_INFO');
  RemClassRegistry.RegisterXSClass(REQUESTOR, 'http//www.yyy.com/IntegratorCoreTypes', 'REQUESTOR');
  RemClassRegistry.RegisterSerializeOptions(REQUESTOR, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(REQUEST_USER, 'http//www.yyy.com/IntegratorCoreTypes', 'REQUEST_USER');
  RemClassRegistry.RegisterSerializeOptions(REQUEST_USER, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(REQUEST_PASSWORD, 'http//www.yyy.com/IntegratorCoreTypes', 'REQUEST_PASSWORD');
  RemClassRegistry.RegisterSerializeOptions(REQUEST_PASSWORD, [xoSimpleTypeWrapper]);
  RemClassRegistry.RegisterXSClass(APIMessage, 'http//www.sx3.com/UpdGetServiceStatusResponse', 'APIMessage');
  RemClassRegistry.RegisterXSClass(MESSAGE_, 'http//www.sx3.com/sx3returnedmessages', 'MESSAGE_', 'MESSAGE');

Snippet 3:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http//schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance" 
xmlns:xs="http//www.w3.org/2001/XMLSchema" 
xmlns:ig="http//www.yyy.com/IntegratorCoreTypes" 
xmlns:ng1="http//www.sx3.com/GET_WORKS_ORDERS_LIST">
  <soap:Header>
    <ig:REQUESTOR>REALREQUESTOR</ig:REQUESTOR>
    <ig:REQUEST_USER>REALREQUEST_USER</ig:REQUEST_USER>
    <ig:REQUEST_PASSWORD>realpassword</ig:REQUEST_PASSWORD>
  </soap:Header>
  <soap:Body>
    <ng1:WorksOrdersListRequest/>
  </soap:Body>
</soap:Envelope>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文