一.delphi做客戶端調用asp.net web service
步驟1. 新建一個vcl工程
步驟2.文件-新建-webservice-WSDLImporter
2.
然后直接next-finish,然后系統(tǒng)會自動生成一個webservice文件,把此文件uses添加到你需要的地方即可,
3.添加THTTPRIO控件的WSDLLocation屬性(設置), 即webservice wsdl 的url
,然后再選擇port和service屬性,都下拉選擇即可
4.由于服務端 其中一個函數(shù)返回的是json數(shù)據(jù),所以要用到TByteArray
數(shù)組,接受字符串一定要用AnsiString,否則用utf8轉換的時候,會有一部分亂碼
主要代碼如下
uses
procedure TForm1.btn1Click(Sender: TObject); var tb: ^TByteArray; tem,tem1:AnsiString; P:PChar; i:Integer; begin end; 二.程序深度分析 返回實際json數(shù)據(jù): [{"memberName":"朱成輝","sexName":"男","idCardNo":"431124199109243419","education":"大專","companyName":"aaa","telephone":"","address":"湖南省道縣新車鄉(xiāng)新車村3組","zoneName":"湖南省長沙市市轄區(qū)","driversType":"C1","newLicenseDate":"2013-08-14","licenseStartDate":"2013-08-14","licenseDuring":"6年","certificateID":"4301000100014000101","certificateType":"客運駕駛員","newCertificateDate":"2013-08-14","certificateBeginDate":"2014-02-20","certificateEndDate":"2020-02-23","faceImage":null}] TByteArray(實際上就是c++里的無符號char 數(shù)組)數(shù)組接受的數(shù)據(jù): (91, 123, 34, 109, 101, 109, 98, 101, 114, 78, 97, 109, 101, 34, 58, 34, 230, 156, 177, 230, 136, 144, 232, 190, 137, 34, 44, 34, 115, 101, 120, 78, 97, 109, 101, 34, 58, 34, 231, 148, 183, 34, 44, 34, 105, 100, 67, 97, 114, 100, 78, 111, 34, 58, 34, 52, 51, 49, 49, 50, 52, 49, 57, 57, 49, 48, 57, 50, 52, 51, 52, 49, 57, 34, 44, 34, 101, 100, 117, 99, 97, 116, 105, 111, 110, 34, 58, 34, 229, 164, 167, 228, 184, 147, 34, 44, 34, 99, 111, 109, 112, 97, 110, 121, 78, 97, 109, 101, 34, 58, 34, 97, 97, 97, 34, 44, 34, 116, 101, 108, 101, 112, 104, 111, 110, 101, 34, 58, 34, 34, 44, 34, 97, 100, 100, 114, 101, 115, 115, 34, 58, 34, 230, 185, 150, 229, 141, 151, 231, 156, 129, 233, 129, 147, 229, 142, 191, 230, 150, 176, 232, 189, 166, 228, 185, 161, 230, 150, 176, 232, 189, 166, 230, 157, 145, 51, 231, 187, 132, 34, 44, 34, 122, 111, 110, 101, 78, 97, 109, 101, 34, 58, 34, 230, 185, 150, 229, 141, 151, 231, 156, 129, 233, 149, 191, 230, 178, 153, 229, 184, 130, 229, 184, 130, 232, 190, 150, 229, 140, 186, 34, 44, 34, 100, 114, 105, 118, 101, 114, 115, 84, 121, 112, 101, 34, 58, 34, 67, 49, 34, 44, 34, 110, 101, 119, 76, 105, 99, 101, 110, 115, 101, 68, 97, 116, 101, 34, 58, 34, 50, 48, 49, 51, 45, 48, 56, 45, 49, 52, 34, 44, 34, 108, 105, 99, 101, 110, 115, 101, 83, 116, 97, 114, 116, 68, 97, 116, 101, 34, 58, 34, 50, 48, 49, 51, 45, 48, 56, 45, 49, 52, 34, 44, 34, 108, 105, 99, 101, 110, 115, 101, 68, 117, 114, 105, 110, 103, 34, 58, 34, 54, 229, 185, 180, 34, 44, 34, 99, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 73, 68, 34, 58, 34, 52, 51, 48, 49, 48, 48, 48, 49, 48, 48, 48, 49, 52, 48, 48, 48, 49, 48, 49, 34, 44, 34, 99, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 84, 121, 112, 101, 34, 58, 34, 229, 174, 162, 232, 191, 144, 233, 169, 190, 233, 169, 182, 229, 145, 152, 34, 44, 34, 110, 101, 119, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 68, 97, 116, 101, 34, 58, 34, 50, 48, 49, 51, 45, 48, 56, 45, 49, 52, 34, 44, 34, 99, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 66, 101, 103, 105, 110, ...) 上面?zhèn)鱽硎莡tf8格式數(shù)組(通過查詢第一個漢字朱的ut8編碼可知 230, 156, 177, 十六進制即E69CB1) 那么為什么返回的數(shù)據(jù)一定要用AnsiString接受呢,無意中看到了一篇文章http://hi.baidu.com/whmtorrent/item/bd7073db261171836cce3f1f 它最后說 我想這也許就是正確答案 關于utf8的文章看http://blog.sina.com.cn/s/blog_9e2e84050102uwhv.html |
|