Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Create (import) using the HTTP POST operation.
Code Examples
Request
| Method | Request URI | HTTP Version |
|---|---|---|
POST |
HTTPS://<HOST>:<PORT>/00000000-0000-0000-0000-000000000000/Modules |
HTTP/1.1 |
Request URI Parameters
The POST operation has no parameters.
Request URI Example
| Example URI |
|---|
POST https://sma-server:9090/00000000-0000-0000-0000-000000000000/Modules HTTP/1.1 |
Request Headers
For more information about the common request headers used by this operation, see Standard Service Management Automation POST/GET/PUT/DELETE Headers.
Request Body
<The request body is encrypted.>
Response
Response Codes
| Response Code | Description |
|---|---|
HTTP/1.1 201 Created |
Request fulfilled. |
Response Headers
For more information about the common response headers used by this operation, see Standard Service Management Automation POST/GET/PUT/DELETE Headers.
Response Body
<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="https://sma-server:9090/00000000-0000-0000-0000-000000000000/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<id>https://sma-server:9090/00000000-0000-0000-0000-000000000000/Modules(guid'41c96c1b-d3ab-43bf-a506-a658811684cd')</id>
<category term="Orchestrator.ResourceModel.Module" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" title="Module" href="Modules(guid'41c96c1b-d3ab-43bf-a506-a658811684cd')" />
<link rel="https://schemas.microsoft.com/ado/2007/08/dataservices/related/Activities" type="application/atom+xml;type=feed" title="Activities" href="Modules(guid'41c96c1b-d3ab-43bf-a506-a658811684cd')/Activities" />
<title />
<updated>2014-04-18T17:50:47Z</updated>
<author>
<name />
</author>
<link rel="edit-media" title="Module" href="Modules(guid'41c96c1b-d3ab-43bf-a506-a658811684cd')/$value" />
<content type="application/octet-stream" src="Modules(guid'41c96c1b-d3ab-43bf-a506-a658811684cd')/$value" />
<m:properties>
<d:ModuleID m:type="Edm.Guid">41c96c1b-d3ab-43bf-a506-a658811684cd</d:ModuleID>
<d:ModuleName>Azure-Portable</d:ModuleName>
<d:TenantID m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:TenantID>
<d:Version m:type="Edm.Int32">0</d:Version>
<d:CreationTime m:type="Edm.DateTime">0001-01-01T00:00:00</d:CreationTime>
<d:LastModifiedTime m:type="Edm.DateTime">0001-01-01T00:00:00</d:LastModifiedTime>
</m:properties>
</entry>
Code Examples
The following example creates (imports) a new Module.
namespace CodeSample.Microsoft.SystemCenter.SMA
{
public class SMASamples
{
public static void Main()
{
// Replace this with the name of your SMA web service endpoint.
string serviceEndPoint = "https://sma-server:9090/00000000-0000-0000-0000-000000000000";
// Setup the connection to SMA
OrchestratorApi SMAService = new OrchestratorApi(new Uri(serviceEndPoint));
// Set credentials to the default or to a specific user.
((DataServiceContext)SMAService).Credentials = CredentialCache.DefaultCredentials;
//((DataServiceContext)SMAService).Credentials = new NetworkCredential("user", "pwd", "domain");
try
{
// Initialize variables with base values.
var modulePath = "C:\\SMA\\Modules\\Azure-Portable.zip";
var moduleName = Path.GetFileNameWithoutExtension(modulePath);
var module = new Module { ModuleName = moduleName };
var moduleReader = new StreamReader(modulePath, Encoding.UTF8);
var zipStream = moduleReader.BaseStream;
var slugHeader = module.ModuleName;
// Set the merge option so that server changes win.
SMAService.MergeOption = MergeOption.AppendOnly;
if (!File.Exists(modulePath))
{
//throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, CmdletResources.FileNotFound, this.ModulePath));
throw new FileNotFoundException("File not found: {0}", modulePath);
}
// Query for the specific module identified by moduleName.
var modules =SMAService.Modules.Where(m => m.ModuleName.Equals(moduleName, StringComparison.InvariantCultureIgnoreCase));
// If the module doesn't exist, add it.
if (modules.Count() == 0)
{
// Add the new module instance to the Modules collection.
// Note: This action is queued up until the SaveChanges action is called.
SMAService.AddToModules(module);
SMAService.SetSaveStream(module, zipStream, true, "application/octet-stream", slugHeader);
// Save all pending actions (client -> server communication initiated).
SMAService.SaveChanges();
}
else
{
Console.WriteLine("A module with the same name already exists.");
Console.ReadLine();
}
}
catch (Exception ex)
{
throw new ApplicationException("An error occurred during execution.", ex.InnerException);
}
}
}
}