Web service misc

本文讨论了客户端调用服务器API的方式对性能的影响,并介绍了如何通过批量请求来提高效率。此外,还对比了WebMessageBodyStyle中Bare与Wrapped两种风格的区别,并提供了XML与JSON格式的具体示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 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,服)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值