Delphi 調(diào)用WebService 直接發(fā)送SOPA報文

有一些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,'&lt;','<',[rfReplaceAll, rfIgnoreCase]);

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

? ? result := StringReplace(result,'&quot;','"',[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);

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 親愛的們,晚安
    村長s1573閱讀 103評論 0 1
  • “世界上只有一種真正的英雄主義,那就是認清生活的真相后依然熱愛生活” ...
    風(fēng)一樣的姑娘閱讀 350評論 0 0
  • “每個人都應(yīng)該有自己主場:人是環(huán)境動物,不管什么環(huán)境,都會有超過你想象的適應(yīng)能力!有一種非常有效提高自己的可行方法...
    計靜怡閱讀 827評論 0 0
  • 有時候喜歡那帶有淡淡憂傷的文字,其實只是因為那會的心境如此,那文字引起了內(nèi)心的共鳴。
    蘇薰閱讀 239評論 0 0

友情鏈接更多精彩內(nèi)容