如何从Visual Studio开发的Android的C#应用程序中访问SoftLayer对象存储。我正在尝试在VS中添加一个Web引用,以便我可以使用存储API服务。我已阅读http://sldn.softlayer.com/reference/objectstorageapihttp://docs.openstack.org/developer/swift/api/object_api_v1_overview.html,但仍无法找到如何做到这一点。如何从Visual Studio开发的Android的C#应用程序中访问SoftLayer对象存储。
0
A
回答
-1
对于使用C#中的SoftLayer,有可用的下一个环节:
https://sldn.softlayer.com/article/C-Sharp
下一个环节提供对象存储信息REST:
http://sldn.softlayer.com/blog/waelriac/managing-softlayer-object-storage-through-rest-apis
下是一个例子如何使用C#与SoftLayer API进行交互。该示例在前面的C#链接之后。
using System;
using Newtonsoft.Json;
namespace GetHubNetworkStorage
{
class Program
{
static void Main(string[] args)
{
string username = "set me";
string apiKey = "set me";
authenticate authenticate = new authenticate();
authenticate.username = username;
authenticate.apiKey = apiKey;
SoftLayer_AccountService accountService = new SoftLayer_AccountService();
accountService.authenticateValue = authenticate;
try
{
// The result is an array of SoftLayer_Network_Storage objects and can be either iterated
// one by one to use the data or being displayed as a JSON value such in this example.
var hubNetworkStorages = accountService.getHubNetworkStorage();
string json = JsonConvert.SerializeObject(hubNetworkStorages, Formatting.Indented);
Console.WriteLine(json);
}
catch (Exception e)
{
Console.WriteLine("Can't retrieve SoftLayer_Network_Storage information: " + e.Message);
}
Console.ReadKey();
}
}
}
下一个环节,如果你决定要设法通过卷曲的对象存储REST的API,但裹成C#代码还可以帮助你:
0
谢谢,非常感谢 - 的下一部分任务是将Android设备上的文件上传到对象存储。代码有点(!)凌乱,缺少错误检查,但希望能指出其他人试图在正确的方向上做到这一点。
var path = Android.OS.Environment.ExternalStorageDirectory ;
var filename = path + Java.IO.File.Separator + string.Format("{0}", prefix) + "mydata.txt";
string username = "SLOS1234567-1:SL1234567";
string apiKey = "1234567891234567891234567891234567891234567891234567891234567891";
string tokenval, URLval, URLcomp;
//Create a web request for authentication.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://syd01.objectstorage.softlayer.net/auth/v1.0");
//Get the headers associated with the request.
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
//Add the X-Auth-User header (for OS user) in the request.
myWebHeaderCollection.Add("X-Auth-User", username);
//Add the X-Auth-Key header (for the API key) in the request.
myWebHeaderCollection.Add("X-Auth-Key",apiKey);
//Get the associated response - the auth token and storage URL.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
tokenval = myHttpWebResponse.GetResponseHeader("X-Auth-Token");
URLval = myHttpWebResponse.GetResponseHeader("X-Storage-Url");
URLcomp = URLval + "/mycontainer/myDirectory/" + string.Format("{0}", prefix) + "mydata.txt";
//Upload the file
WebClient wc = new WebClient();
wc.Headers.Add("X-Auth-Token",tokenval);
wc.UploadFile(URLcomp, "PUT", filename);
相关问题
- 1. Ember.js:如何从应用程序对象访问存储
- 2. 如何在C#中使用应用程序需要Internet访问的Android开发?
- 3. 如何从ExpressJS中的模块访问应用程序对象?
- 4. 如何在Visual Studio中开发的C#应用程序中添加空白行?
- 5. 从FineUploader上传到SoftLayer对象存储
- 6. 如何在Visual Studio 2008中开发Windows Mobile应用程序?
- 7. Visual Studio 2015 Android NDK应用程序开发构建失败visual C++
- 8. 在Android应用程序中访问手机的内部存储?
- 9. 如何在Android中存储对象,以便即使重新启动应用程序时也可访问对象
- 10. SoftLayer的对象存储验证端点
- 11. Android应用程序开发与C#
- 12. Android:如何访问使用FileOutputStream存储的对象
- 13. 如何访问Windows应用程序包中的文件存储应用程序
- 14. 用于将文件发送到对象存储的Softlayer http API
- 15. 如何使用Visual Studio 2017与Qt开发GUI应用程序?
- 16. 直接从Android应用程序访问云存储
- 17. 在java中使用softlayer对象存储创建IBM bluemix应用程序。我已经使用softlayer帐户
- 18. 开发Android应用程序与Visual Studio 2008
- 19. Android开发:访问其他应用程序的活动
- 20. 访问存储为BLOB的Java对象的MYSQL存储过程
- 21. 创建和Lua中访问的Lua对象,存储在C++程序
- 22. Visual Studio中的WPF开发应用程序工具
- 23. 在Android应用程序中存储Facebook访问令牌
- 24. Android应用程序开发 - 相机应用程序的问题
- 25. 如何在softlayer对象存储中启用CORS
- 26. 如何在SoftLayer对象存储中启用CORS?
- 27. Visual Studio应用程序的数据库访问问题
- 28. 如何访问Silverlight类库中的应用程序对象?
- 29. 如何从控制台应用程序访问应用程序对象?
- 30. Visual Studio Android开发中的应用程序UI构建器不起作用