delphi7调用c#写的webservice(.net2.0)
网上翻一下,东拼西凑的找到方法
不懂delphi的可以跟我做:
1,引入webservice单元,delphi7 menu>>File>>New>>other>>Webservices>>WSDLimporter>>填入你的webservice地址+?WSDL>>finish
2,修改这个文件,在首部users加入对OPconvert的引用
3,在相关区域加入代码,主要是对UTF8的设置
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
//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
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
//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
4,还是这个文件 ,在结束之前加入
initialization
InvRegistry.RegisterInterface(TypeInfo(StatisticsSoap), 'http://www.??????.net/webservice', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(StatisticsSoap), 'http://www.??????.net/webservice/%operationName%');
//add---------to support new document type
InvRegistry.RegisterInvokeOptions(TypeInfo(StatisticsSoap), ioDocument);
//add---------END
end.
InvRegistry.RegisterInterface(TypeInfo(StatisticsSoap), 'http://www.??????.net/webservice', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(StatisticsSoap), 'http://www.??????.net/webservice/%operationName%');
//add---------to support new document type
InvRegistry.RegisterInvokeOptions(TypeInfo(StatisticsSoap), ioDocument);
//add---------END
end.
5,然后 就可以调用它们了,要注意一点,不能通过WSDLLocation来设置地址,因为delphi的封装存在问题,不能识别.net2.0的一些新节点。
方法一:
var
mHttpRIO: THTTPRIO;
mServiceSoap: statisticsSoap;
begin
mHttpRIO := THTTPRIO.Create(nil);
try
mHttpRIO.HTTPWebNode.UseUTF8InHeader :=True;
mHttpRIO.Converter.Options :=mHttpRIO.Converter.Options + [soUTF8InHeader,soUTF8EncodeXML];
mHttpRIO.URL := 'http://www.??????.net/webservice/statistics.asmx';
//mHttpRIO.URL := 'http://localhost:3589/Statistics.asmx'; //only for test
mServiceSoap := mHttpRIO as statisticsSoap;
mHttpRIO: THTTPRIO;
mServiceSoap: statisticsSoap;
begin
mHttpRIO := THTTPRIO.Create(nil);
try
mHttpRIO.HTTPWebNode.UseUTF8InHeader :=True;
mHttpRIO.Converter.Options :=mHttpRIO.Converter.Options + [soUTF8InHeader,soUTF8EncodeXML];
mHttpRIO.URL := 'http://www.??????.net/webservice/statistics.asmx';
//mHttpRIO.URL := 'http://localhost:3589/Statistics.asmx'; //only for test
mServiceSoap := mHttpRIO as statisticsSoap;
方法二:
var
mServiceSoap:StatisticsSoap;
begin
mServiceSoap:=GetStatisticsSoap;
mServiceSoap.XXXXXX('XXX','XXX','XXX');
mServiceSoap:StatisticsSoap;
begin
mServiceSoap:=GetStatisticsSoap;
mServiceSoap.XXXXXX('XXX','XXX','XXX');
ok ,搞定交差。