本文介绍了SOAP客户端中的Array_Of_Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用客户端调用SOAP方法时,我遇到一个非常有趣的问题,我必须传递一个类型为Array_Of_Int(Array_Of_Int = Integer的数组)的参数,问题是当在请求中生成数组时,则会生成以下

I have a very interesting issue when I call a SOAP method with my client, I must pass a parameter which is of type Array_Of_Int(Array_Of_Int = array of Integer), the problem is that when the array is being generated in the request, it generates the following

<ArrayParam>
  <item>12345</item>
  <item>23456</item>
  <item>34567</item>
</ArrayParam>

但是我相信服务器期望

<ArrayParam>12345</ArrayParam>
<ArrayParam>23456</ArrayParam>
<ArrayParam>34567</ArrayParam>

我很确定Delphi在RegisterSerializeOptions或RegisterInvokeOptions中都有解决此问题的方法

I'm pretty sure that Delphi has a workaround for this issue somehow in the RegisterSerializeOptions or RegisterInvokeOptions however I can't seem to find the issue, thoughts?!

谢谢大家的时间,我使用的是Delphi 2010。

Thank you all for your time, I'm using Delphi 2010.

编辑:如布鲁诺提到的那样,为了解决此问题,我们需要在生成的.pas文件的初始化部分中添加以下代码:

in order to fix this issue, as Bruneau mentioned, we need to have the following code added in the initialization section of generated .pas file:

InvRegistry.RegisterInvokeOptions(TypeInfo(< ServerInterfaceNameHere>),ioDocument);

但是,这还会带来另一个问题命名空间,作为一种快速而美观的解决方案,我在THTTPRio的OnBeforeExecute方法中添加了以下代码

However that imposes another issue, the namespace, as a quick and pretty elegant fix, I've added the following code in the THTTPRio's OnBeforeExecute method

procedure TMyDataModule.MyRioBeforeExecute(const MethodName: string; SOAPRequest: TStream);

  procedure FixNamespaces;
  var
    LStrings: TStringList;
  begin
    LStrings := TStringList.Create;
    try
      SOAPRequest.Position := 0;
      LStrings.LoadFromStream(SOAPRequest);
      SOAPRequest.Position := 0;
      SOAPRequest.Size := 0;
      LStrings.Text := StringReplace(LStrings.Text, MethodName, 'NS1:' + MethodName, [rfReplaceAll]);
      LStrings.Text := StringReplace(LStrings.Text, MethodName + ' xmlns', MethodName + ' xmlns:NS1', []);
      LStrings.SaveToStream(SOAPRequest);
      SOAPRequest.Position := 0;
    finally
      FreeAndNil(LStrings);
    end; // tryf
  end; // procedure FixNamespaces;

begin
  FixNamespaces;
end;

以上只是一个的修正,我真的希望我能找到一个如果有人知道,可以更干净,更优雅地解决此问题,请务必发布您的答案

The above is just a fix, I really hope I can find a much cleaner and elegant solution to this issue, if anyone knows, please DO post your answer.

推荐答案

由于没有人愿意发布答案或对解决此问题没有其他想法,因此我将发布我的修复,直到其他人可以提出比编辑请求更优雅的解决方案。

Since no one cares to post their answer or have no other idea on how to fix this issue, I'll just post my fix until others can come out with a more elegant solution than editing the request.

确保在导入WSDL文件时生成的* .pas文件的初始化部分中添加了下一行代码(非常感谢Bruneau指出了这一点)

Make sure the next line of code is added in the initialization section of the *.pas file generated when you imported the WSDL file(big thanks to Bruneau for pointing this out)

InvRegistry.RegisterInvokeOptions(TypeInfo(< ServerInterfaceNameHere>),ioDocument);

但是这带来了另一个问题,即名称空间,这是一种快速而又优雅的解决方案,我在THTTPRio的OnBeforeExecute方法中添加了以下代码

However that imposes another issue, the namespace, as a quick and pretty elegant fix, I've added the following code in the THTTPRio's OnBeforeExecute method

procedure TMyDataModule.MyRioBeforeExecute(const MethodName: string; SOAPRequest: TStream);

  procedure FixNamespaces;
  var
    LStrings: TStringList;
  begin
    LStrings := TStringList.Create;
    try
      SOAPRequest.Position := 0;
      LStrings.LoadFromStream(SOAPRequest);
      SOAPRequest.Position := 0;
      SOAPRequest.Size := 0;
      LStrings.Text := StringReplace(LStrings.Text, MethodName, 'NS1:' + MethodName, [rfReplaceAll]);
      LStrings.Text := StringReplace(LStrings.Text, MethodName + ' xmlns', MethodName + ' xmlns:NS1', []);
      LStrings.SaveToStream(SOAPRequest);
      SOAPRequest.Position := 0;
    finally
      FreeAndNil(LStrings);
    end; // tryf
  end; // procedure FixNamespaces;

begin
  FixNamespaces;
  // other possible issue to be fixed -- if any
end;

这篇关于SOAP客户端中的Array_Of_Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 10:29