Use serviceruntime assembly to interact with Windows azure

Source: Internet
Author: User
Use serviceruntime assembly to interact with Windows azure

1. serviceruntime Assembly position

2. Determine whether the application runs on Fabric

3. Read servicedefinition. csdef Configuration File Content

1. Add serviceruntime Assembly reference

If you create a cloud project in vs2010, the following references will be automatically added:

However, if you want to migrate the applicationProgramTo the cloud, you must manually add the Assembly reference. The location is as follows:

2. serviceruntime

Serviceruntime builds a bridge between Windows azure and applications. Through serviceruntime, common Asp.net Web applications can interact with azure. This interaction is usually manifested in the following three aspects:

    • Check whether the current application is running on the cloud
    • Read servicedefinition. csdef configuration file information
    • Obtain a reference from the local cache to operate the local cache.
3. Does the current application run on the cloud?

<Asp: Label runat = "server" id = "runninginthefabriclabel"> </ASP: Label>

This. runninginthefabriclabel. Text = <br/> roleenvironment. isavailable? "Running in fabric": "Not in fabric ";

4. Use servicedefinition. csdef configuration file 4.1 servicedefinition. csdef configuration file structure

The name indicates the name of the solution in Vs, followed by the configuration information of each web role.

4.2 How do I change this configuration file? Is there a GUI tool?

Servicedefinition. csdef files are stored in XML format and are directly opened in XML form. In vs, only prompts are available. Of course, you can also use the GUI tool:

4.3 endpoints Configuration

Types are divided into input and Internal. Input indicates that the system can respond to external requests. Internal indicates that the system is only used internally in the application and cannot be accessed externally. Protocol indicates the protocol used: HTTP and HTTPS.

4.4 configuration Configuration

1. the default trust level is full trust. Generally, the released program runs on Windows azure partial trust. However, if you need to perform some special work, such as P/invoke, set the trust level to full.

2. instance count indicates the number of role instances started. VM Size: VM Size

3. startup action is actually a configuration option of Vs, which indicates the action in the debugging status. Here, it indicates starting the browser.

4.5 local storage Configuration

Because the data storage on the cloud and the server running the application may be different from the same server, the local storage ensures that the data storage of the local storage size runs on the same server as the application. The last option "clean on recycle" indicates whether the data is saved in some special circumstances. The following shows how to read data from these loca Storage

<Asp: button id = "button1" runat = "server" text = "write to local storage" <br/> onclick = "button#click"/> <br /> <br/> <Table> <br/> <tr> <br/> <TD> <br/> Local Storage name </TD> <br /> <TD> <br/> <asp: label id = "localstoragenamelabel" runat = "server"> </ASP: label> <br/> </TD> <br/> </tr> <br/> <TD> <br/> <Table class = "style1"> <br/> <tr> <br/> <TD> <br/> local storage size </TD> <br/> </tr> <br/> </table> <br/> </TD> <br/> <asp: label id = "localstoragesizelabel" runat = "server" text = "label"> </ASP: label> <br/> </TD> <br/> </tr> <br/> <TD> <br/> <Table class = "style1"> <br/> <tr> <br/> <TD> <br/> Local Storage rootpath </TD> <br/> </tr> <br/> </table> <br/> </TD> <br/> <asp: label id = "localstoragerootpathlabel" runat = "server" text = "label"> </ASP: label> <br/> </TD> <br/> </tr> <br/> </table>

Protected void button#click (Object sender, eventargs e) <br/>{< br/> localresource localstorage = roleenvironment. getlocalresource ("mylocalstorage"); <br/> This. localstoragenamelabel. TEXT = localstorage. name; <br/> This. localstoragesizelabel. TEXT = localstorage. maximumsizeinmegabytes. tostring (); <br/> This. localstoragerootpathlabel. TEXT = localstorage. rootpath; </P> <p> file. writealltext (localstora GE. rootpath + "helloworld.txt", "Hello world! "); <Br/>}

After obtaining the path through localstorage. rootpath, the original. Net operations on the file path can be used.

CodeDownload

This series of blogs are all personal insights when learning the Windows azure platform, which inevitably has shortcomings. please correct me and leave a message to give your valuable comments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.