有一些WebService使用D7的HTTPRIO控件已經(jīng)不能正常調(diào)用了,
這個時候可以直接使用HTTPReqResp控件直接發(fā)送報文,
或者使用TIdHTTP控件 http?post方式請求 webservicessoap協(xié)議接口
函數(shù)示例:
HTTPReq: THTTPReqResp;
function TDM_Demo.WebSrvMain( In_fkey_XML,In_funccode,In_fparam_XML:String):String;
var
? DataMsg:WideString;
? strStream, strSend: TStringStream;
begin
//使用SOPAUI等工具獲得標準示例報文DataMsg
? DataMsg:='<?xml version="1.0" encoding="utf-8"?>'+
? '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+
? ' xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '+
? 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
? 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
'<SOAP-ENV:Body>'+
'<m:funMain xmlns:m="http://services.dtshis/">'+
'<In_fkey_XML><![CDATA['+In_fkey_XML+']]></In_fkey_XML>'+
'<In_funccode>'+In_funccode+'</In_funccode>'+
'<In_fparam_XML><![CDATA['+In_fparam_XML+']]></In_fparam_XML>'+
? '</m:funMain></SOAP-ENV:Body></SOAP-ENV:Envelope>';
? strStream := TStringStream.Create('');
? strSend := TStringStream.Create(AnsiToUtf8(DataMsg));//Utf8轉(zhuǎn)碼
? try
? ? HTTPReq.url := '服務(wù)地址';
? ? HTTPReq.Execute(strSend, strStream);
? ? result := strStream.DataString;
? ? result := UTF8Decode(result);
//xml? ? < >? "? 轉(zhuǎn)碼
? ? result := StringReplace(result,'<','<',[rfReplaceAll, rfIgnoreCase]);
? ? result := StringReplace(result,'>','>',[rfReplaceAll, rfIgnoreCase]);
? ? result := StringReplace(result,'"','"',[rfReplaceAll, rfIgnoreCase]);
//轉(zhuǎn)為delphi XMLDocument 文檔
? ? result := StringReplace(result,'<?xml version="1.0" encoding="UTF-8"?>',
? ? ? '<?xml version="1.0" encoding="gb2312"?>',[rfReplaceAll, rfIgnoreCase]);
? finally
? ? strStream.Free;
? ? strSend.Free;
? end;
end;
http? post方式請求 webservices?soap協(xié)議接口
with IdHttp do
? ? begin
? ? ? ProtocolVersion := pv1_1;
? ? ? AllowCookies := True;
? ? ? ProxyParams.BasicAuthentication := False;
? ? ? ProxyParams.ProxyPort := 0;
? ? ? Request.ContentLength := -1;
? ? ? Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
? ? ? Request.BasicAuthentication := False;
? ? ? Request.ContentType := 'application/x-www-form-urlencoded';
? ? ? HTTPOptions :=[hoKeepOrigProtocol, hoInProcessAuth];
? ? ? ReadTimeout:=5000;
? ? end;
? ? strSend.WriteString(DataMsg);
? ? result:=IdHttp.Post(sWSDLAddr,strSend);