C# WebService中的函数
[WebMethod]
public string Test_Pro(string vString)
{
return vString;
}Delphi中调用为:
var
d:ServiceSoap;
begin
d:=GetServiceSoap();
Caption:= d.Test_Pro('asdasdasdasd');但是调用出错,但是VS调试又是正确的,不晓得怎么办?
[WebMethod]
public string Test_Pro(string vString)
{
return vString;
}Delphi中调用为:
var
d:ServiceSoap;
begin
d:=GetServiceSoap();
Caption:= d.Test_Pro('asdasdasdasd');但是调用出错,但是VS调试又是正确的,不晓得怎么办?
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://localhost/MyWebService/Example.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2007-2-28 12:19:12 - 1.33.2.5)
// ************************************************************************ //unit Example;interfaceuses InvokeRegistry, SOAPHTTPClient, 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.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema" // ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// binding : ExampleSoap
// service : Example
// port : ExampleSoap
// URL : http://localhost/MyWebService/Example.asmx
// ************************************************************************ //
ExampleSoap = interface(IInvokable)
['{444725B4-3750-586C-5497-8EE30CDE10B9}']
function HelloWorld: WideString; stdcall;
function getStr(const s: WideString): WideString; stdcall;
end;function GetExampleSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ExampleSoap;
implementationfunction GetExampleSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ExampleSoap;
const
defWSDL = 'http://localhost/MyWebService/Example.asmx?wsdl';
defURL = 'http://localhost/MyWebService/Example.asmx';
defSvc = 'Example';
defPrt = 'ExampleSoap';
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 ExampleSoap);
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;
initialization
InvRegistry.RegisterInterface(TypeInfo(ExampleSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ExampleSoap), 'http://tempuri.org/%operationName%');
InvRegistry.RegisterInvokeOptions(TypeInfo(ExampleSoap), ioDocument);end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,SoapHTTPClient,InvokeRegistry, Types, XSBuiltIns;
type
ExampleSoap = interface(IInvokable)
['{444725B4-3750-586C-5497-8EE30CDE10B9}']
function HelloWorld: WideString; stdcall;
function getStr(const s: WideString): WideString; stdcall;
end; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
X :THTTPRio;
InterfaceVariable: ExampleSoap;
begin
X :=THTTPRio.Create(nil);
x.HTTPWebNode.UseUTF8InHeader:=true;
x.WSDLLocation:='http://localhost/MyWebService/Example.asmx?wsdl';
InterfaceVariable := X as ExampleSoap;
showmessage(InterfaceVariable.HelloWorld);
showmessage(InterfaceVariable.getStr('hello world'));
x.Free;
end;
initialization
InvRegistry.RegisterInterface(TypeInfo(ExampleSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ExampleSoap), 'http://tempuri.org/%operationName%');
InvRegistry.RegisterInvokeOptions(TypeInfo(ExampleSoap), ioDocument);
end.
在生成的Service.pas的initialization里面加上这么一句话
ITelWebServiceSoap :TelWebServiceSoap;
RoutesObj : ArrayOfRoute;
error : ErrorInfo;
begin
ITelWebServiceSoap :=(HTTPRIO1 as TelWebServiceSoap);//这样转一下
error:=ITelWebServiceSoap.CheckUser('aa','aa');
Memo1.Lines.Clear;
if error.m_bERROR=false then
begin
Memo1.Lines.Add(错误信息!'+error.m_ERROR_INFO);
exit;
end;
ITelWebServiceSoap.GetRouteListByCode('aa',2,Surveyid.Text,error,RoutesObj);
if error.m_bERROR=false then //---³ö´í ûÓлñÈ¡µ½Êý¾Ý
begin
Memo1.Lines.Add(取得数据:'+error.m_ERROR_INFO);
end
else
begin
Memo1.Lines.Add(IntToStr(Length(RoutesObj)));
end;
ITelWebServiceSoap.Exit;
end;
用的是 “hongqi162”的一样方法
HTTPRIO1:=THTTPRIO.Create(Application);
Area:=nil;
HTTPRIO1.WSDLLocation:='http://locahost:8080/services/MandiQ?wsdl';//java写的Web Services的访问方法
try
(HTTPRIO1 as MandiQPortType).getAllTradeBig;
except
Application.MessageBox('连接Web Service失败!','提示',MB_ICONERROR );
end;