Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings!

I got a silly question, for I'd like to get some aid. I'm practicing the call of Web Services from Delphi7. I'm testing it with a WS made in C# 2010. That is what I got so far:

This is the Web Service in C#:
C#
public class Service1 : System.Web.Services.WebService
{
    [WebMethod]
    public int countChars(string text)
    {
        int n = 0;
        if (text != null)
            return text.Length;
        else
            return n;
    }
}


This is the Web Client in Delphi (just a form with a button and a SOAP object):
Delphi
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, InvokeRegistry, Rio, SOAPHTTPClient, StdCtrls, Service1;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Serv: THTTPRIO;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   size : Integer;
begin
   try
      size := (Serv as Service1Soap).countChars('Hello');
      ShowMessage(IntToStr(size));
   except
      on e:Exception do
      begin
         ShowMessage(e.Message);
      end
   end
end;

end.


The thing is, when I do call the web service, text is received as a null entry, instead of the word "Hello".

What I have tried:

I tried changing to PChar in Delphi. Looking for info on internet. Even read about BTSr but no idea how to use that (I supose that's for COM stuff). I wonder why I keep getting a null string. What am I missing?



Edited: Seems like I'm getting a similar issue with Integers. Tried to do an addittion between 2 numbers (4 and 5) and I get 0 as result.

C# Web Method:
C#
[WebMethod]
public int sumAB(int a, int b)
{ return a + b; }


Delphi call to Method:
Delphi
procedure TForm1.Button1Click(Sender: TObject);
var
   sum, a, b : Integer;
begin
   a := 5;
   b := 4;
   sum:= (Serv as Service1Soap).sumAB(a,b);
   ShowMessage(IntToStr(sum));
end;
Posted
Updated 9-Jul-19 9:55am
v4

1 solution

Solved.

Needed to add a line in Service1.pas

Original:
Delphi
initialization
  InvRegistry.RegisterInterface(TypeInfo(Service1Soap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), 'http://tempuri.org/%operationName%');
end.


New:
Delphi
initialization
  InvRegistry.RegisterInterface(TypeInfo(Service1Soap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Service1Soap), 'http://tempuri.org/%operationName%');
  InvRegistry.RegisterInvokeOptions(TypeInfo(Service1Soap), ioDocument);
end.


As you can see, I added a "RegisterInvokeOptions" function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900