Web service misc

来源:互联网 发布:淘宝刷流量 猎流 编辑:程序博客网 时间:2024/04/30 04:28
  • If client invokes server in loop as follows, it will have bad performance.

 Client:

 foreach ()

{

invoke server

}

In order to improve performance, client should invoke serve once (get a collection of results) as follows, then client will handle these results in loop.

Client:

collection results = invoke server;

foreach (result in results)

{

handle result;

}

  • WebMessageBodyStyle
我们知道请求消息和回复消息分别是对操作方法输入参数和返回值(输出参数和引用参数)的封装,WebMessageBodyStyle中的Bare表示请求消息和回复消息的主体部分仅仅包含针对输入参数和返回值(输出参数和引用参数)序列化后的内容,而Wrapped则会在外面包装一个基于当前操作的“封套”。枚举项WrappedRequest和WrappedResponse用于单独针对请求消息和回复消息的主体进行封装。

比如:

xml:

Bare:

 1: 请求消息主体:
   2: <Employee xmlns="http://www.artech.com/" 
   3:   xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   4:   <Department>行政部</Department>
   5:   <Grade>G9</Grade>
   6:   <Id>003</Id>
   7:   <Name>王五</Name>
   8: </Employee>
Wrapped:
 1: 请求消息主体:
   2: <Create xmlns="http://tempuri.org/">
   3:   <employee xmlns:a="http://www.artech.com/" 
   4:         xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   5:     <a:Department>行政部</a:Department>
   6:     <a:Grade>G9</a:Grade>
   7:     <a:Id>003</a:Id>
   8:     <a:Name>王五</a:Name>
   9:   </employee>
  10: </Create>

Json:
Bare:
   1: 请求消息主体:
   2: {"Department":"行政部","Grade":"G9","Id":"003","Name":"王五"}
Wrapped:
  1: 请求消息主体:
   2: {"employee":{"Department":"行政部","Grade":"G9","Id":"003","Name":"王五"}}


  • If client has cache, it should get data from cache first; if not found, then get data from server again.
  • Getting data from server and updating UI should process asynchronously.
  • If client calling web service failed, you can copy url to browser to see what happens. (there will be some detailed information for failure.)
  • Response status code: 1xx(information,不), 2xx (ok,好), 3xx(redirect,转), 4xx(client error,客), 5xx(server error,服)

原创粉丝点击