![在 Azure 服务器上部署 Web API MVC4 时出错](https://linux22.com/image/762705/%E5%9C%A8%20Azure%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E9%83%A8%E7%BD%B2%20Web%20API%20MVC4%20%E6%97%B6%E5%87%BA%E9%94%99.png)
请求的 VM 层目前在东南亚不适用于此订阅。请尝试其他层或部署到其他位置
这是我的 API 代码:
使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Net;使用 System.Net.Http;使用 System.Web;使用 System.Web.Http;使用 System.Web.Mvc;使用 System.Linq.Expressions;使用 System.Windows.Media.Imaging;使用 System.IO;使用 System.Runtime.Serialization;使用 System.Runtime.Serialization.Formatters.Binary;使用 SourceAFIS.Simple;//导入命名空间 SourceAFIS.Simple 使用 System.Drawing;使用 System.ComponentModel;使用 System.Net;命名空间 MvcApplication2.Controllers {公共类 ValuesController:ApiController {静态 AfisEngine AFIS = new AfisEngine();静态 Person DatabasePersons = new Person();静态 Person CandidatePerson = new Person();静态 Fingerprint DatabaseFingerprints = new Fingerprint();静态 Fingerprint CanditateFingerprint = new Fingerprint(); // 从 Fingerprint 继承以添加 Filename 字段 [Serializable] class MyFingerprint : Fingerprint { public string Filename; }
// Inherit from Person in order to add Name field
[Serializable]
class MyPerson : Person
{
public string Name;
}
// Initialize path to images
static readonly string ImagePath = Path.Combine(Path.Combine("..", ".."), "images");
// Shared AfisEngine instance (cannot be shared between different threads though)
static AfisEngine Afis;
// Take fingerprint image file and create Person object from the image
static MyPerson Enroll(string filename, string name)
{
Console.WriteLine("Enrolling {0}...", name);
// Initialize empty fingerprint object and set properties
MyFingerprint fp = new MyFingerprint();
fp.Filename = filename;
// Load image from the file
Console.WriteLine(" Loading image from {0}...", filename);
BitmapImage image = new BitmapImage(new Uri(filename, UriKind.RelativeOrAbsolute));
fp.AsBitmapSource = image;
// Above update of fp.AsBitmapSource initialized also raw image in fp.Image
// Check raw image dimensions, Y axis is first, X axis is second
Console.WriteLine(" Image size = {0} x {1} (width x height)", fp.Image.GetLength(1), fp.Image.GetLength(0));
// Initialize empty person object and set its properties
MyPerson person = new MyPerson();
person.Name = name;
// Add fingerprint to the person
person.Fingerprints.Add(fp);
// Execute extraction in order to initialize fp.Template
Console.WriteLine(" Extracting template...");
Afis.Extract(person);
// Check template size
Console.WriteLine(" Template size = {0} bytes", fp.Template.Length);
return person;
}
public HttpResponseMessage Post()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
var httpRequest = HttpContext.Current.Request;
var a = httpRequest.Form.GetValues(0);
Console.WriteLine(a);
if (httpRequest.Files.Count < 1)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
System.IO.Stream fs = httpRequest.Files[0].InputStream;
System.IO.BinaryReader br=new System.IO.BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));
Bitmap bitmap1 = (Bitmap)tc.ConvertFrom(bytes);
DatabaseFingerprints.AsBitmap = new Bitmap(bitmap1);
DatabasePersons.Fingerprints.Add(DatabaseFingerprints);
var wc = new WebClient();
var imgStream = new MemoryStream(wc.DownloadData((a[0])));
System.IO.BinaryReader br1 = new System.IO.BinaryReader(imgStream);
Byte[] bytes1 = br1.ReadBytes((Int32)imgStream.Length);
TypeConverter tc1 = TypeDescriptor.GetConverter(typeof(Bitmap));
Bitmap bitmap2 = (Bitmap)tc1.ConvertFrom(bytes1);
CanditateFingerprint.AsBitmap = new Bitmap(bitmap2);
CandidatePerson.Fingerprints.Add(CanditateFingerprint);
// Extracting skeletons of database fingerprints and candidate fingerprint.
AFIS.Extract(DatabasePersons);
AFIS.Extract(CandidatePerson);
// Matching
bool res = false;
float score = AFIS.Verify(CandidatePerson, DatabasePersons);
bool match = (score > 40);
int points = Convert.ToInt32(score);
if (match)
{
Console.WriteLine(string.Format("Fingerprint match with {0} points", points.ToString()));
res = true;
}
else
{
Console.WriteLine(string.Format("Fingerprint does not match with {0} points", points.ToString()));
res = false;
}
return Request.CreateResponse(HttpStatusCode.Created,res);
}
}
}
答案1
这与您的代码无关,您尝试创建的 VM 大小在所选区域中不可用。您需要将 VM 大小或区域更改为可用的大小或区域。