引用程序集:System.Configuration.dll
窗本构造函数中添加以下代码:
var baseAddress = ConfigurationManager.AppSettings["baseAddress"]; var config = new HttpSelfHostConfiguration(baseAddress); config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); var cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors); var server = new HttpSelfHostServer(config); server.OpenAsync().Wait();
App.config文件中添加以下内容:
<appSettings> <add key="baseAddress" value="http://localhost:9002" /> </appSettings>
时间: 2024-11-05 20:45:57