Delphi calls C # to write the WebService parameter null solution with Chinese garbled problem

Source: Internet
Author: User

(GO) Delphi calls C # write the WebService parameter null solution with Chinese garbled problem

//Add------- toSupport UTF-8
RIO. Httpwebnode.useutf8inheader: = true; //adds the row, specifying that the UTF is used-8 Code Transfer
RIO. Converter.encoding:='UTF-8 ';
RIO. Converter.options:=RIO. Converter.options+
[soutf8inheader,soutf8encodexml];
//Add-------END

Testing the webservice of. NET 2.0 today has found a big problem. Just can't get the parameter, the parameter is always null. Of course. Use a. NET call
Without any problems, the Web test page is also normal. Whether the result of Delphi7 or Java calls is the same, is it a bug for. NET 2.0?

Test results found: value type parameters are all default values, reference types are all null

The code for WebService is as follows:



[WebMethod]
public string echostring (string args)
{
return args;
}

[WebMethod]
public string echoint (int args)
{
return args. ToString ();
}



Code for Delphi Calls


Procedure Tform1.button3click (Sender:tobject);
Var
Ss:servicesoap;
hello:widestring;
Begin
Try
HTTPRIO1. Wsdllocation: = Edtaddress.text;
HTTPRIO1. Service: = edit3. Text;
HTTPRIO1. Port: = Edit4. Text;

SS: = (HTTPRIO1 as Servicesoap);
hello:= ' Hello ';
MEMO1.LINES.ADD (ss. Echoint (234));
Except
On E:exception do
ShowMessage (E.message);
End
End


---------------------------------------------------------------------------------------------------

-----------------------------------------------

There is no problem in trying to find vs2003 generated web Services,delphi calls, even if delphi2006 is not normal

Call the Web Service for. NET 2.0.

Finally, after unremitting efforts, finally found a way that is in the Delphi generated WebServices declaration unit added to the row
Invregistry.registerinvokeoptions (TypeInfo (Servicesoap), iodocument);

Such as:


Unit Service;

Interface

Uses Invokeregistry, soaphttpclient, Types, Xsbuiltins;

Type
Servicesoap = Interface (iinvokable)
[' {77573149-9c57-fa51-f11f-efd527c91bd9} ']
function HelloWorld (const asdf:widestring): widestring; stdcall;
End

Implementation

Type

Servicesoapimpl = Class (Tinvokableclass, Servicesoap)
Public
{Servicesoap}
function HelloWorld (const asdf:widestring): widestring; stdcall;
End

function Servicesoapimpl.helloworld (const asdf:widestring): widestring;
Begin
{Todo-implement Method HelloWorld}
End

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);//That's the line.
End.
So the problem is done. But after my tests found, still not ... Found another reason for the problem
Solved,


It is possible to add the Soaprpcserviceattribute attribute to the class attribute of WebService written with VS2005.
as follows:
[SoapRpcService (routingstyle=soapserviceroutingstyle.soapaction)]

(go) Delphi calls C # write the WebService parameter null solution with Chinese garbled problem

Related Article

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.