Array_Of_Int in SOAP client

后端 未结 2 1220
你的背包
你的背包 2021-01-15 00:26

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

2条回答
  •  鱼传尺愫
    2021-01-15 00:57

    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.

    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(), ioDocument);

    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;
    

提交回复
热议问题