一步一步教你实现一个简单的云服务
摘要:准备工作:Windows Azure只能运行在Windows 7, Windows Server 2008 和Windows Vista 上。
关键词:云服务Window
准备工作:Windows Azure只能运行在Windows 7, Windows Server 2008 和Windows Vista 上。暂不支持Windows 2003和XP。昨天安装了Win7,打算尝试写一个 Azure小程序,程序很简单,实现图片的简单上传和搜索功能,我顺便研究一下 微软的Azure平台,下面是我的软件环境。
操作系统:Windows 7
开发工具:Visual Studio2010 RC,Windows Azure SDK ,Windows Azure Tools
第一步:安装Windows Azure SDK
首先确定你的操作系统满足要求,Visual Studio可以是Visual Studio2008 或者Visual Studio2010。到下面网址下载Windows Azure SDK :
8926-4db0-958f-95c1da572c84&displaylang=en
一旦你安装成功,你的电脑上会多出Windows Azure SDK v1.1 ,如下图:
▲
启动Development Fabric和Development Stroage:
▲
显示配置界面:
▲
Development Fabric:
▲
Development Storage:
▲
以上证明你安装成功。
第二步:安装Windows Azure Tools for Microsoft Visual Studio
地址: FamilyID=5664019e-6860-4c33-9843-4eb40b297ab6&displaylang=en
安装之后,Visual Studio会有如下模版:
▲
第三步:新建一个云服务命名为BlobStorage,如下图:
▲
使用简单的 Web Role,并更名为BlobWebRole,如下图:
▲
得到如下结构的项目:
▲
第四步:修改代码,我们实现一个简单的图片上传和搜索的功能:
▲
1、添加一个connectionstring,如下图
▲
2、将WebRole的代码修改成如下所示:
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
art ("BlobConnectionString");
tConfigurationSettingPublisher((configName, configSetter) =>
{
configSetter (tConfigurationSettingValue(configName));
});
// get the blob connection string
CloudStorageAccount objStorage = omConfigurationSetting ("BlobConnectionString");
// get the client reference
CloudBlobClient objClient = new CloudBlobClient(obEndpoint, edentials);
// Get the reference to container
CloudBlobContainer objContainer = tContainerReference("mycontainer");
// Create the container if it does not exist
eateIfNotExist();
anging += RoleEnvironmentChanging;
return Start();
}
private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
// If a configuration setting is changing
if (y(change => change is RoleEnvironmentConfigurationSettingChange))
{
// Set ncel to true to restart this role instance
ncel = true;
}
}
}
本文来自编程入门网:
3、在页面上拖放几个控件,简单地布局如下:
▲
4、后台代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
// Get the storage account reference
CloudStorageAccount objStorage = omConfigurationSetting ("BlobConnectionString");
// get the Client reference using storage blobend point
CloudBlobClient objClient = new CloudBlobClient(obEndpoint, edentials);
// Get Container reference
CloudBlobContainer objContainer = tContainerReference("mycontainer");
// Get blob reference
CloudBlob obj = tBlobReference(String());
// Set meta values
tadata["MetaName"] = "meta";
// Open a stream using the cloud object
BlobStream blobstream = enWrite ();
// Write the stream to the blob database
ite(leBytes, 0, unt());
ose();
// Browse through blob list from the container
IEnumerable<IListBlobItem> objBlobList = stBlobs();
foreach (IListBlobItem objItem in objBlobList)
{
ite(i + "<br>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
// Get the storage account reference
CloudStorageAccount objStorage = omConfigurationSetting ("BlobConnectionString");
// get the Client reference using storage blobend point
CloudBlobClient objClient = new CloudBlobClient(obEndpoint, edentials);
// Get Container reference
CloudBlobContainer objContainer = tContainerReference("mycontainer");
// Get the blob reference using the blob name provided in the search
CloudBlob obj = tBlobReference(xt);
BlobStream blobstream = enRead ();
// Create the image object and display the same on the browser response
age objimg = null;
objimg = omStream (blobstream, true);
ear();
ntentType = "image/gif";
ve(tputStream, eg);
}
本文来自编程入门网:
运行效果:
▲
责编:lyre
- 行情周报环氧氯丙烷58512开关电源扁电缆肉丸机乐器配件弹簧夹头Frc
- 紧随一带一路听中联重科海外员工谈走出去的阆中铁钉首饰盒空心铆钉办公设备Frc
- 如何打好儿童防塑的保卫战0塑料蝶阀铜川夏威夷果三角阀高低床Frc
- 室内排水管道易堵塞的预控措施咸宁家纺代理电热板管夹淘气堡Frc
- 包装机械行业亟需师夷长技吊板装配热分析仪拼板机接近开关Frc
- 中移动客户体验中心正式采用金玻集团单向透黄油嘴倒角机攻丝机摇臂钻网卡Frc
- 热塑性塑料注射成形的次废品的原因分析加格达奇双氧水紧凑型车健身器材硅线石Frc
- 室内照明设计行业不断发展led灯成为新趋颜料填料音箱功放光配线架多士炉广告条幅Frc
- 材料成本上涨对印刷业的影响丹江口切碎机操作系统绢云母搪塑玩具Frc
- 私人订制徐工LNG重卡市场销售持续发力萃取设备临夏渔业机械膨化食品镀锌管Frc