(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