Delphi 調用C#編寫的WebService 參數為Null解決方案

來源:互聯網
上載者:User
今天測試.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)]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.