當前位置:編程學習大全網 - 源碼下載 - Delphi 調用WebService 直接發送SOPA報文

Delphi 調用WebService 直接發送SOPA報文

有壹些WebService使用D7的HTTPRIO控件已經不能正常調用了,

這個時候可以直接使用HTTPReqResp控件直接發送報文,

或者使用TIdHTTP控件 http?post方式請求 webservices soap 協議接口

函數示例:

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轉碼

? try

HTTPReq.url := ' 服務地址 ';

HTTPReq.Execute(strSend, strStream);

result := strStream.DataString;

result := UTF8Decode(result);

//xml < >? "? 轉碼

result := StringReplace(result,'<','<',[rfReplaceAll, rfIgnoreCase]);

result := StringReplace(result,'>','>',[rfReplaceAll, rfIgnoreCase]);

result := StringReplace(result,'"','"',[rfReplaceAll, rfIgnoreCase]);

//轉為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 協議接口

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);

  • 上一篇:應對操作系統安全漏洞的基本方法是什麽?(多選)
  • 下一篇:任務升級源代碼
  • copyright 2024編程學習大全網