Coder Social home page Coder Social logo

aliyun / aliyun-openapi-net-sdk Goto Github PK

View Code? Open in Web Editor NEW
537.0 72.0 627.0 33.87 MB

Alibaba Cloud SDK for .NET

Home Page: https://www.nuget.org/profiles/aliyun-openapi-sdk

License: Other

C# 99.99% JavaScript 0.01%
alibaba alibabacloud sdk client dotnet csharp alibabacloud-sdk net net-core

aliyun-openapi-net-sdk's Introduction

English | 简体中文

Alibaba Cloud SDK for .NET

Travis Build Status Appveyor Build Status Codecov Nuget Version Nuget Version Nuget Version

The Alibaba Cloud SDK for .NET allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), CloudMonitor, etc. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.

Troubleshoot

Troubleshoot Provide OpenAPI diagnosis service to help developers locate quickly and provide solutions for developers through RequestID or error message.

Online Demo

OpenAPI Workbench provides the ability to call the cloud product OpenAPI online, generates SDK Example code dynamically and retrieves interface quickly, which can lessen the difficultly of using the Alibaba Cloud API significantly.

Requirements

  • The Alibaba Cloud SDK for .NET requires:
    • .NET Framework 4.5 and above
    • .NET Standard 2.0 and above
    • C# 4.0 and above

Installation

You should install ECS Nuget Package when you are using ECS Product. If you want to install a specific version, please add --version or it will install the latest version of this package.

Use .NET CLI ( Recommand )

dotnet add package aliyun-net-sdk-ecs

Use Package Manager

Install-Package aliyun-net-sdk-ecs

Quick Examples

At the beginning, you need to sign up for an Alibaba Cloud account and retrieve your Credentials.

Note: To increase the security of your account, we recommend that you can use the AccessKey of the RAM user to access Alibaba Cloud services.

Initiate a call

The following code example show three main steps to use the Alibaba Cloud SDK for .NET:

  • Create and initialize a DefaultAcsClient instance.

  • Create a request and set parameters.

  • Initiate the request and handle the response.

using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Ecs.Model.V20140526;

class Program
{
    static void Main(string[] args)
    {
        // Create a client used for initiating a request
        IClientProfile profile = DefaultProfile.GetProfile(
            "<your-region-id>",
            "<your-access-key-id>",
            "<your-access-key-secret>");
        DefaultAcsClient client = new DefaultAcsClient(profile);

        try
        {
            // Create the request
            DescribeInstancesRequest request = new DescribeInstancesRequest();
            request.PageSize = 10;

            // Initiate the request and get the response
            DescribeInstancesResponse response = client.GetAcsResponse(request);
            System.Console.WriteLine(response.TotalCount);
        }
        catch (ServerException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
        catch (ClientException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
    }
}

Use BearerToken to invoke CCC Product

You should install the CCC Product Nuget Package if you want to run the below demo in your local machine.

using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.CCC.Model.V20170705;

class Program
{
    static void Main(string[] args)
    {
        // Create a client used for initiating a request
        var profile = DefaultProfile.GetProfile("<your-region-id>");
        var bearerTokenCredentialProvider = new BearerTokenCredentialProvider("<your-bearertoken>");

        var client = new DefaultAcsClient(profile, bearerTokenCredentialProvider);

        try
        {
            // Create the request
            var request = new ListPhoneNumbersRequest();

            // Initiate the request and get the response
            var response = client.GetAcsResponse(request);
            
            // Do something as you want below
        }
        catch (ServerException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
        catch (ClientException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
    }
}

Documentation

Issues

Opening an Issue, Issues not conforming to the guidelines may be closed immediately.

Changelog

Detailed changes for each release are documented in the release notes.

API Reference

You can visit the API and its parameters in Product List.

License

Apache-2.0

FOSSA Status

aliyun-openapi-net-sdk's People

Contributors

aliguyong avatar axiosleo avatar conan425 avatar doublnt avatar fenglc avatar fossabot avatar ivanzhangwb avatar jacksontian avatar jxyowen avatar laiwang avatar liaoyustudent avatar liyan2011 avatar peze avatar qingtang-sdk avatar sdk-team avatar talentning avatar wuling0412 avatar yndu13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aliyun-openapi-net-sdk's Issues

安装sdk后无法解析Ecs

无法解析一下路径:
using Aliyun.Acs.Esc.Model.V20140526;

the type or namespace name 'Ecs' does not exist in the namespace 'Aliyun.Acs'

项目生成失败

Your project is not referencing the ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "frameworks" section of your project.json, and then re-run NuGet restore. aliyun-net-sdk-core.vs2010
package文件没有

.net 4.6.1 从nuget上安装 cdn sdk, 使用时会报错 未能加载文件或程序集“System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)

未能加载文件或程序集“System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)

二义性和已包含错误

1>------ 已启动全部重新生成: 项目: aliyun-net-sdk-ecs, 配置: Debug Any CPU ------
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ModifyAutoSnapshotPolicyExRequest.cs(91,17,91,37): error CS0102: The type 'ModifyAutoSnapshotPolicyExRequest' already contains a definition for 'autoSnapshotPolicyId'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ModifyAutoSnapshotPolicyExRequest.cs(104,17,104,39): error CS0102: The type 'ModifyAutoSnapshotPolicyExRequest' already contains a definition for 'autoSnapshotPolicyName'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ModifyAutoSnapshotPolicyExRequest.cs(117,17,117,27): error CS0102: The type 'ModifyAutoSnapshotPolicyExRequest' already contains a definition for 'timePoints'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ModifyAutoSnapshotPolicyExRequest.cs(130,17,130,31): error CS0102: The type 'ModifyAutoSnapshotPolicyExRequest' already contains a definition for 'repeatWeekdays'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ModifyAutoSnapshotPolicyExRequest.cs(143,15,143,28): error CS0102: The type 'ModifyAutoSnapshotPolicyExRequest' already contains a definition for 'retentionDays'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ApplyAutoSnapshotPolicyRequest.cs(85,17,85,37): error CS0102: The type 'ApplyAutoSnapshotPolicyRequest' already contains a definition for 'autoSnapshotPolicyId'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ApplyAutoSnapshotPolicyRequest.cs(98,17,98,24): error CS0102: The type 'ApplyAutoSnapshotPolicyRequest' already contains a definition for 'diskIds'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\CreatePhysicalConnectionRequest.cs(107,15,107,24): error CS0102: The type 'CreatePhysicalConnectionRequest' already contains a definition for 'bandwidth'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\CreateAutoSnapshotPolicyRequest.cs(89,17,89,39): error CS0102: The type 'CreateAutoSnapshotPolicyRequest' already contains a definition for 'autoSnapshotPolicyName'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\CreateAutoSnapshotPolicyRequest.cs(102,17,102,27): error CS0102: The type 'CreateAutoSnapshotPolicyRequest' already contains a definition for 'timePoints'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\CreateAutoSnapshotPolicyRequest.cs(115,17,115,31): error CS0102: The type 'CreateAutoSnapshotPolicyRequest' already contains a definition for 'repeatWeekdays'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\CreateAutoSnapshotPolicyRequest.cs(128,15,128,28): error CS0102: The type 'CreateAutoSnapshotPolicyRequest' already contains a definition for 'retentionDays'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\ModifyPhysicalConnectionAttributeRequest.cs(92,15,92,24): error CS0102: The type 'ModifyPhysicalConnectionAttributeRequest' already contains a definition for 'bandwidth'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\CancelAutoSnapshotPolicyRequest.cs(83,17,83,24): error CS0102: The type 'CancelAutoSnapshotPolicyRequest' already contains a definition for 'diskIds'
1>D:\GIT\aliyun-openapi-net-sdk\aliyun-net-sdk-ecs\Ecs\Model\V20140526\DeleteAutoSnapshotPolicyRequest.cs(83,17,83,37): error CS0102: The type 'DeleteAutoSnapshotPolicyRequest' already contains a definition for 'autoSnapshotPolicyId'
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========

先编译 aliyun-net-sdk-core 然后引入到 aliyun-net-sdk-ecs 中进行编译,输出以上错误,C#方面是菜鸟,请求指导。

vs2015

LoadEndpointDocument()会报NullReferenceException异常

运行环境 :

.NET Core 2.1
aliyun.acs.core.netcore 1.1.4.1 通过 nuget 安装

在使用Aliyun.Acs.Dysmsapi 发送短信的时候,会出现异常

异常详细信息

System.Xml.XmlReader.CalcBufferSize(Stream input)
System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, string baseUriStr, Stream stream, byte[] bytes, int byteCount, Encoding encoding)
System.Xml.XmlTextReaderImpl..ctor(string url, Stream input, XmlNameTable nt)
System.Xml.XmlDocument.Load(Stream inStream)
Aliyun.Acs.Core.Regions.InternalEndpointsParser.LoadEndpointDocument()
Aliyun.Acs.Core.Regions.InternalEndpointsParser.GetEndpoints()
Aliyun.Acs.Core.Profile.DefaultProfile.GetEndPointsFromLocal()
Aliyun.Acs.Core.Profile.DefaultProfile.GetEndpoints(string regionId, string product, Credential credential, string locationProduct)
Aliyun.Acs.Core.DefaultAcsClient.DoAction<T>(AcsRequest<T> request, bool autoRetry, int maxRetryNumber, IClientProfile profile)
Aliyun.Acs.Core.DefaultAcsClient.DoAction<T>(AcsRequest<T> request)
Aliyun.Acs.Core.DefaultAcsClient.GetAcsResponse<T>(AcsRequest<T> request)

经过简单的debug后发现
InternalEndpointsParser这个类中,获取xml文件的方法

Assembly.GetExecutingAssembly().GetManifestResourceStream(name)

取到的值为空,下面是调试窗口输出的信息

Assembly.GetExecutingAssembly().GetManifestResourceStream("Aliyun.Acs.Core.Regions.endpoints.xml")
null

似乎是 xml的路径的问题,使用 下面这个方法

 this.GetType().GetTypeInfo().Assembly.GetManifestResourceNames()
    {string[1]}
        [0]: "Aliyun.Acs.Core.NetCore.Regions.endpoints.xml"

返回的Aliyun.Acs.Core.NetCore.Regions.endpoints.xml能够获取到xml的信息,而程序获取的路径Aliyun.Acs.Core.Regions.endpoints.xml取不到

AcsResponse的子类为什么要重复定义RequestId?

AcsResponse里已经有RequestId了,子类又来一个RequestId,隐式隐藏了父类的RequestId。
当有如下泛型方法时:

private T Request<T>(AcsRequest<T> request) where T : AcsResponse
{
    var requestInfo = new APIRequestInfo();
    try
    {
        var result = m_IMMClient.GetAcsResponse(request);
        requestInfo.RequestId = result.RequestId;
        return result;
    }
    catch (Exception ex)
    { ... }
}

其中取RequestId的值,就不会取到子类的值,而是父类的RequestId,实际为null。
我就被这个给坑了啊。。。

aliyun-net-sdk-core 1.1.12 版本导致SDK.InvalidRegionId

最新代码中的 endpoints.xml 导致 iot 调用服务时发生SDK.InvalidRegionId 错误。

回退到 1.1.8 版后,问题解决。

原因是 endpoints.xml 中对 iot 服务地址的定义没有了,regional_endpoint_pattern 也没有发挥作用:

  <product> 
    <code>iot</code>  
    <location_service_code>iot</location_service_code>  
    <document_id>30557</document_id>  
    <regional_endpoints></regional_endpoints>  
    <global_endpoint/>  
    <regional_endpoint_pattern>iot.[RegionId].aliyuncs.com</regional_endpoint_pattern> 
  </product>  

aliyun-net-sdk-core 1.1.9更新提示警告

Package 'aliyun-net-sdk-core 1.1.9' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

Package 'aliyun-net-sdk-core 1.1.9' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.

表达式的计算结果必须为节点集

代码

static void Main(string[] args)
        {
            var profile = DefaultProfile.GetProfile("cn-hangzhou", "************", "************");
            var client = new DefaultAcsClient(profile);
            var request = new GetWhoisInfoRequest();
            request.DomainName = "aliyun.com";
            
            try
            {
                var response = client.GetAcsResponse<GetWhoisInfoResponse>(request);
                Console.WriteLine(response.DomainName);
            }
            catch(ServerException ex)
            {
                Console.WriteLine("ServerException");
                Console.WriteLine(ex.ErrorCode);
                Console.WriteLine(ex.Message);
            }
            catch (ClientException ex)
            {
                Console.WriteLine("ClientException");
                Console.WriteLine(ex.ErrorCode);
                Console.WriteLine(ex.Message);
            }
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            Console.Read();
        }

出错信息

未经处理的异常:  System.Xml.XPath.XPathException: 表达式的计算结果必须为节点集。
   在 MS.Internal.Xml.XPath.XPathParser.ParseNodeTest(AstNode qyInput, AxisType axisType, XPathNodeType nodeType)
   在 MS.Internal.Xml.XPath.XPathParser.ParseStep(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseRelativeLocationPath(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseLocationPath(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParsePathExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseUnionExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseUnaryExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseMultiplicativeExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseAdditiveExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseRelationalExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseEqualityExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseAndExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseOrExpr(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseExpresion(AstNode qyInput)
   在 MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)
   在 System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
   在 System.Xml.XPath.XPathNavigator.Select(String xpath)
   在 System.Xml.XmlNode.SelectNodes(String xpath)
   在 Aliyun.Acs.Core.Reader.XmlReader.Read(XmlNode element, String path, Boolean appendPath)
   在 Aliyun.Acs.Core.Reader.XmlReader.Read(XmlNode element, String path, Boolean appendPath)
   在 Aliyun.Acs.Core.Reader.XmlReader.Read(String xml, String endpoint)
   在 Aliyun.Acs.Core.DefaultAcsClient.ReadResponse[T](AcsRequest`1 request, HttpResponse httpResponse, Nullable`1 for
   在 Aliyun.Acs.Core.DefaultAcsClient.ParseAcsResponse[T](AcsRequest`1 request, HttpResponse httpResponse)
   在 Aliyun.Acs.Core.DefaultAcsClient.GetAcsResponse[T](AcsRequest`1 request)

cdn sdk内文件缺失

cdn sdk内缺失IsGreyUserRequest.cs/IsGreyUserResponse.cs/IsGreyUserResponseUnmarshaller.cs

aliyun-net-sdk-core获取语音识别token失败

使用aliyun-net-sdk-core获取语音识别token失败,代码如下:
`public static string GetToken()
{
IClientProfile profile = DefaultProfile.GetProfile(region_id, ak_id, ak_secret);
DefaultAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.Domain = "nls-meta.cn-shanghai.aliyuncs.com";
request.Version = "2018-05-18";
request.UriPattern = "/pop/2018-05-18/tokens";
request.Method = Aliyun.Acs.Core.Http.MethodType.POST;

        CommonResponse response = client.GetCommonResponse(request);
        String result = response.Data;
        return result;
    }`

http返回状态200,返回数据:{} (空的json)
同样的参数通过python sdk返回正常数据

DefaultAcsClient's DoAction<T> overload methods have BUG

Error Code

FormatType? requestFormatType = request.AcceptFormat;
if (null != requestFormatType)
{
	format = requestFormatType;
}

Right Code

if (null == format)
{
	format = request.AcceptFormat;
}

I see that this method has Nullable type parameter format.
I thought you were going to judge if the parameter format was empty, otherwise the code if (null != requestFormatType) would be meaningless. Because it's always true.

ECS SDK无法编译,clone下来的代码中有一些空文件

例如Transform/V20140526/下的
DescribeTagKeysResponseUnmarshaller.cs
AllocatePublicIpAddressResponseUnmarshaller.cs
等多个虽然有大小但内容均为二进制0的文件

clone的代码最后一个commit:f4335d05ba0272f60e08300257188977f3148484

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.