阿里云sdk:https://develop.aliyun.com/sdk/csharp?spm=5176.doc27234.2.4.QiJb9l

Github:https://github.com/aliyun/aliyun-openapi-net-sdk

云直播产品页面:https://www.aliyun.com/product/live?spm=5176.7960203.237031.168.LRN4J3

 

SDK使用:

步骤

第一步,需要初始化Client。

1.与阿里云SDK相关的类都在名称空间 Aliyun.Api 下;
2.AliyunClient 是与 Open API 交互的接口,SDK 的操作都是通过 IAliyunClient 完成的;
3.AliyunClient 可以复用,建议设置成应用程序全局唯一的;
4.用户可以调用 SetTimeout 方法来设置SDK调用接口的连接超时时间。
示例代码如下:

private static string serverUrl = "<serverUrl>";//http://slb.aliyuncs.com/
private static string accessKeyId = "<accessKeyId>";
private static string accessKeySecret = "<accessKeySecret>";

private static IAliyunClient client = new DefaultAliyunClient(serverUrl, accessKeyId, accessKeySecret);

第二步, 实例化request,给请求实例赋值并调用API获取返回结果。

调用步骤
1.实例化一个请求类,根据调用的API的不同版本实例化不同命名空间下的请求类;
2.给请求类实例赋值;
3.调用接口返回调用结果。

包名称规则:
请求类名称空间:Aliyun.Api.[PPP].[PPP][yyyymmdd].Request
响应类命名空间:Aliyun.Api.[PPP].[PPP][yyyymmdd].Response
[PPP]为产品名称缩写大写;[yyyymmdd]为API版本号

下面以负载均衡 API 2014-05-15版为例,SLB对应产品名称,20140515对应调用的API版本。
请求类名称空间:Aliyun.Api.SLB.SLB20140515.Request
响应类名称空间:Aliyun.Api.SLB.SLB20140515.Response

下面以创建SLB实例为例,给出示例代码如下:

public static void CreateLoadBalancer()
{
        CreateLoadBalancerRequest request = new CreateLoadBalancerRequest();
        request.RegionId = "<RegionId>";
        request.AddressType = "<AddressType>";
        request.Bandwidth = <Bandwidth>
        request.InternetChargeType = "<InternetChargeType>";

        try
        {
                CreateLoadBalancerResponse response = client.Execute(request);
                if (string.IsNullOrEmpty(response.Code))
                {//创建成功
                String loadBlancerId = response.LoadBalancerId;//取得实例ID
                }
                else
                {//创建失败
                String errorCode = response.Code;//取得错误码
                String message = response.Message;//取得错误信息
                }
        }
        catch (Exception e)
        {
                //TODO: handle exception
        }
}

查看 API

安装SDK后,您可以通过调用API来访问、管理阿里云产品,以下是阿里云开放的API的产品,选择产品查看产品API详细说明。

posted on 2016-07-29 11:33  kingreatwill  阅读(3388)  评论(0编辑  收藏  举报