//add-------to support UTF-8
RIO.HTTPWebNode.UseUTF8InHeader := true; //添加該行,指定採用UTF-8代碼傳輸
RIO.Converter.Encoding:='UTF-8';
RIO.Converter.Options:=RIO.Converter.Options + [soUTF8InHeader,soUTF8EncodeXML];
//add-------END
今天測試.net 2.0的WebService,發現了一個大問題。就是沒法獲取參數,參數永遠是null。固然了使用.net調用
沒有任何問題,web測試頁也正常。不管是Delphi7仍是java調用的結果的都是同樣的,難道是.net 2.0的Bug?
測試結果發現:值類型參數所有爲缺省值,引用類型所有爲null
WebService的代碼以下:
[WebMethod]
public string EchoString(string args)
{
return args;
}
[WebMethod]
public string EchoInt(int args)
{
return args.ToString();
}
delphi調用的代碼
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;
---------------------------------------------------------------------------------------------------
-----------------------------------------------
在不斷嘗試中發現vs2003生成的web Services,delphi調用的時候不會有任何問題,即便是delphi2006也沒法正常
調用.net 2.0的Web Service.
最後通過不懈努力,終於找到方法那就是在delphi生成webservices聲明單元中加入以行
InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);
如:
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);//就是這一行
end.
至此問題搞定了。
可是通過個人測試發現,仍是不行.......找到了其餘緣由問題
解決了,
在用VS2005寫的WebService的類屬性中加入SoapRpcServiceAttribute屬性就能夠了。
如 下: [SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.SoapAction)]