Issues to be aware of when calling. NET 2.0 WebService with Delphi7 (document format and UTF8 encoding)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.