zoukankan      html  css  js  c++  java
  • IdHttpServer实现webservice(130篇DataSnap文章)

    IdHttpServer实现webservice

     

    朋友有个项目,通信协议使用HTTP,数据序列使用BIN(二进制)。他不知道要选用何种技术方案。

    REST webservice是http+json,SOAP webservice是http+xml,好像都不适合。

    于是想到了使用INDY的TidHttpServer控件来实现。TidHttpServer是可以实现webservice中间件的。

    限于篇幅,省略若干代码。

    中间件代码:

    //设置绑定参数
    IdHTTPServer1.Bindings.Clear;
    IdHTTPServer1.DefaultPort:= 8000;
    IdHTTPServer1.Bindings.Add.IP := '127.0.0.1';
    //启动服务器
    IdHTTPServer1.Active := True;

    procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
    ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    begin
    memo1.Lines.Add(ARequestInfo.Document) ;
    memo1.Lines.Add(arequestinfo.Params.Values['t1']) ;
    memo1.Lines.Add(arequestinfo.Params.Values['t2']);
    end;

    IE浏览器输入:http://127.0.0.1:8000/test?t1=china&t2=cxg

    中间件执行效果图:

    上面是通过HTTP的GET方法调用中间件的方法和传递参数,同样,HTTP的POST也可以。

    寥寥数行,就能实现一个超级无敌简单的WEBSERVICE 中间件。不知道诸位看出来了,这么简单的中间件却有一个灵活的地方:它的数据序列格式可以是TEXT、JSON、XML或者BIN等。

    http://www.cnblogs.com/hnxxcxg/p/3395524.html
    ------------------------------------------------------------------
    我仿照了 这个教程。 结果没反应,帮忙看下 问题出在哪里。 多谢老师

    你那个是实现webservice的,有啥用,还得apache
    你就用idhttpserver然后实现一个简单的http服务器,内嵌一个html页面,可以post数据到你的服务器上,idhttpserver响应post消息并保存到当前目录下就ok了

  • 相关阅读:
    苏教版国标本小学语文第一册汉字笔画
    C++ preprocessor __VA_ARGS__ number of arguments
    The Aggregate Magic Algorithms
    USB Mass Storage大容量存储的基本知识
    【转】驱动和应用层的三种通信方式
    Do You Actually Know What *P++ Does In C?
    Repeat Macro Cloak
    A SCSI command code quick reference
    USB device layout, descriptors, interface alternate setting
    RTOS Semaphore Services
  • 原文地址:https://www.cnblogs.com/findumars/p/5236918.html
Copyright © 2011-2022 走看看