webservice用的是c#(Vs2005)的代码:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    public Service() 
    {
        //如果使用设计的组件,请取消注释以下行 
        //InitializeComponent(); 
    }    [WebMethod]
    public int Sub(int a, int b)//两个整数相减
    {
     return a - b;
    }
}下面是自动生成的service.pas:
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://10.18.1.27/webService/Service.asmx?WSDL
// Encoding : utf-8
// Version  : 1.0
// (2009-05-04 13:23:01 - $Revision:   1.9.1.0.1.0.1.9  $)
// ************************************************************************ //unit Service;interfaceuses InvokeRegistry, Types, XSBuiltIns;type  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Borland types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:int             - "http://www.w3.org/2001/XMLSchema"
  // ************************************************************************ //
  // Namespace : http://tempuri.org/
  // soapAction: http://tempuri.org/Sub
  // transport : http://schemas.xmlsoap.org/soap/http
  // binding   : ServiceSoap
  // service   : Service
  // port      : ServiceSoap
  // URL       : http://10.18.1.27/webService/Service.asmx
  // ************************************************************************ //
  ServiceSoap = interface(IInvokable)
  ['{77573149-9C57-FA51-F11F-EFD527C91BD9}']
    function  Sub(const a: Integer; const b: Integer): Integer; stdcall;
  end;function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''): ServiceSoap;
implementation
  uses SOAPHTTPClient;function GetServiceSoap(UseWSDL: Boolean; Addr: string): ServiceSoap;
const
  defWSDL = 'http://10.18.1.27/webService/Service.asmx?WSDL';
  defURL  = 'http://10.18.1.27/webService/Service.asmx';
  defSvc  = 'Service';
  defPrt  = 'ServiceSoap';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  RIO := THTTPRIO.Create(nil);
  try
     if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
    Result := (RIO as ServiceSoap);
  finally
    if Result = nil then
      RIO.Free;
  end;
end;
initialization
  InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'http://tempuri.org/', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'http://tempuri.org/Sub');end. 调用web服务的代码:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,StdCtrls, DB, ADODB,InvokeRegistry, Rio, SOAPHTTPClient ;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementationuses Service;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  rtn: Integer;
  ws: ServiceSoap;
begin
  ws:= GetServiceSoap(false,'');
  rtn:= ws.Sub(13,5);//计算13减去5的结果
  showmessage('返回结果: '+ intToStr(rtn));
end;end.比较费解的是返回的结果一直“0”,但用C#调用时没有问题的
请高手帮忙,问题出在哪里?

解决方案 »

  1.   

    我试了一下,如果在web service加入如下函数的话,用delphi调用是可以得到"Hello World",但就是不能得到Sub的计算结果:
     [WebMethod]
     public string HelloWorld()
     {
      return "Hello World";
     }
      

  2.   

    在service单元的“initialization”加入:
    InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);
      

  3.   

    InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);