Platform Technology-.NET SDK Instructions for Use


Environment dependencies

  • .NET Framework 2.0 and above (Windows Phone platform is not supported)

Usage example

Get Taobao current System time

ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TimeGetRequest req = new TimeGetRequest();
TimeGetResponse rsp = client.Execute(req);
Console.WriteLine(rsp.Body);

Get single transaction details

ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TradeFullinfoGetRequest req = new TradeFullinfoGetRequest();
req.Fields = "tid,type,status,payment,orders";
req.Tid = 123456789L;
TradeFullinfoGetResponse rsp = client.Execute(req, sessionKey);
Console.WriteLine(rsp.Body);

Listen to real-time message notification

TmcClient client = new TmcClient("app_key", "app_secret", "default"); 
client.OnMessage += (s, e) => 
{ 
    try 
    { 
        Console.WriteLine(e.Message.Content); 
        Console.WriteLine(e.Message.Topic);
        // 默认不抛出异常则认为消息处理成功 
    } 
    catch (Exception exp) 
    { 
        Console.WriteLine(exp.StackTrace); 
        e.Fail(); // 消息处理失败回滚,服务端需要重发 
    } 
}; 
client.Connect("ws://mc.api.taobao.com/");

Batch call API

BatchTopClient client = new BatchTopClient("http://gw.api.taobao.com/router/batch", "appkey", "appsecret", "json");
TimeGetRequest timeRequest = new TimeGetRequest();
AppipGetRequest ipRequest = new AppipGetRequest();
TopBatchRequest batch = new TopBatchRequest();
batch.AddRequest(timeRequest).AddRequest(ipRequest);
TopBatchResponse rsp = client.Execute(batch);
Console.WriteLine(rsp.Body);

Service address

API service address

QQ截图20170213154955.png

Message service address

QQ截图20170213155016.png

Advanced features

Does not interpret the response string as Object (the object contained in XxxResponse is null at this time)

DefaultTopClient.SetDisableParser(true)

Use a simplified JSON structure to return, remove redundant JSON nodes

DefaultTopClient.SetUseSimplifyJson(true)

Cancel API call log management

DefaultTopClient.SetDisableTrace(true)

Ignore HTTPS certificate check (recommended to only open in test environment)

DefaultTopClient.SetIgnoreSSLCheck(true)

Cancel response to GZIP compression function (GZIP compression function can significantly reduce network transmission, it is strongly recommended not to cancel)

DefaultTopClient.SetUseGzipEncoding(false)

Set the HTTP connection timeout and read timeout (can be increased appropriately if the network environment is poor)

// HTTP等待请求开始返回的超时时间:默认20秒
DefaultTopClient.SetTimeout(20000L)
// HTTP等待读取数据完成的超时时间:默认60秒
DefaultTopClient.SetReadWriteTimeout(60000L)

Modify the log management storage path

DefaultTopLogger.FilePath = "c:/tmp/topsdk.log";

API call Automatically retry when errors occur (generally, ISP errors can be retried successfully)

AutoRetryTopClient client = new AutoRetryTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
client.SetMaxRetryCount(3);
client.SetRetryWaitTime(100L);
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.Execute(request);
if (!response.IsError) {
    Console.WriteLine(response.Body);
}

API call nearest routing (select the nearest TOP computer room to call based on the location where the API call is initiated)

ClusterTopClient client = new ClusterTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.Execute(request);
Console.WriteLine(response.Body);

Notes

  • ITopClient implementation classes are all thread-safe, so there is no need to create a new ITopClient implementation class for every API request
  • Create an instance of ITopClient implementation class When specifying format=json, compared with xml format, it can reduce the amount of data transmission and improve the efficiency of API requests

FAQ

  • There is no FAQ## about this document yet.
#