Delphi7 An error occurred while calling the. NET 2.0-based webservice developed by Vs.net 2005. Check the data http://www.community.borland.com/article/borcon/files/4132/paper/4132.html found the original DELPHI7 client although support WebService RPC | Encoded and document| Literal encoding, but the default is to use RPC. The webservice in. NET 2.0 is the default with documnet| Literal encoded. So we need to make a statement to let the Delphi client adopt Documnet| The literal code will do. In the Delphi WSDL importer produced the WebService interface file, add the following line:
Initialization
Invregistry.registerinterface (TypeInfo (servicesoap), ' http://tempuri.org/', ' utf-8 ');
Invregistry.registerinvokableclass (Servicesoapimpl);
Invregistry.registerdefaultsoapaction (TypeInfo (servicesoap), ' Http://tempuri.org/HelloWorld ');
Invregistry.registerinvokeoptions (TypeInfo (Servicesoap), iodocument);//indicates that Delphi uses document encoding
End.
If you need to transfer the parameters of Chinese characters in WebService, it is recommended to add another line of code in Service.pas
function Getservicesoap (Usewsdl:boolean; addr:string; Httprio:thttprio): Servicesoap;
Const
defwsdl = ' http://localhost/myservice/service.asmx?wsdl ';
Defurl = ' http://localhost/myservice/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
If Httprio = Nil Then
RIO: = Thttprio. Create (Nil)
Else
RIO: = Httprio;
RIO. Httpwebnode.useutf8inheader:
= True
;Add the line, specifying the UTF-8 code transfer
Try
Result: = (RIO as Servicesoap);
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
It should be noted that using Delphi2006 does not require the above changes to properly invoke the WebService written by Vs.net 2005.
Http://www.cnblogs.com/sonicit/archive/2007/06/02/768753.html
Issues to be aware of when calling. NET 2.0 WebService with Delphi7 (document format and UTF8 encoding)