使用Visual Studio,我创建了一个带有api(8个apiControllers)的控制台应用程序。在我的本地机器上,它工作得很好,在我同事的机器上也没有问题。当把exe文件复制到WindowsServer2012R2上时,出现了一个问题,api监听端口为44311。exe正在运行。但是,当我在浏览器中试图得到一些答案时,什么也没有出现(在浏览器中,我必须输入网址:"我")。https:/localhost:44311BitViseTest。).API有一个swagger,但是在浏览器中,swagger也是什么都不返回,只有'this site is not available'的错误。
using System;
using System.Configuration;
namespace BitViseApi
{
class Program
{
static void Main(string[] args)
{
string domainAddress = ConfigurationManager.AppSettings["domainAddress"];
using (WebApp.Start(url: domainAddress))
{
Console.WriteLine("Service Hosted " + domainAddress);
System.Threading.Thread.Sleep(-1);
}
}
}
}
程序.cs: Startup.cs:
using Owin;
using System.Web.Http;
namespace BitViseApi
{
class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
HttpConfiguration config = new HttpConfiguration();
config.EnableCors();
config.Routes.MapHttpRoute(
name: "createUserApi",
routeTemplate: "Bitvise/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// This is the call to our swashbuckle config that needs to be called
SwaggerConfig.Register(config);
appBuilder.UseWebApi(config);
}
}
}
BitViseController.cs的开始。
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Cors;
using BssCfg815Lib;
using System.Security.Cryptography;
using System.Text;
using NLog;
namespace BitVise
{
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class VirtAccountsController : ApiController
{
public IEnumerable<LocalVirtAccount815> Get(string username, string password)
{
string result;
BitViseHelper helper = new BitViseHelper();
helper.Log(LogLevel.Info, "Call to VirtAccounts. Login: username=" + username + ", password=" + password);
bool loginOkay = helper.CheckUser(username, password, out result);
if (!loginOkay)
{
helper.Log(LogLevel.Error, " Login failed: " + result);
return null;
}
helper.Log(LogLevel.Info, " Login succeeded.");
List<LocalVirtAccount815> virtAccounts = helper.ListVirtAccounts();
helper.Log(LogLevel.Info, " " + virtAccounts.Count + " Virtual accounts retrieved.");
return virtAccounts;
}
} // VirtAccountsController
...
...
(在图片中,浏览器中的网址有误,应该是 "BitViseController.cs"。应该是 https:/localhost:44311BitViseTest。但结果是一样的)。)
有谁知道我忘记了什么,或者我做错了什么?
先谢谢大家了。
Cor
问题是:端口被定义为 "http"。s:/localhost:44311".将其定义为'。http:/localhost:44311。'解决了这个问题:-。