如何调试发布到OWIN服务?

时间:2015-07-14 14:56:09

标签: c# web-services owin middleware

我有一个OWIN自助主机服务。

另一项服务(我无权访问)是通过本地网络IP地址向其发送数据(虽然计算机名称给出了相同的结果)。

我遇到的问题是控制器中的值总是为“空”。

我尝试过小提琴,但cannot see任何流量。我知道它正在发送正确的数据,因为另一项服务(我也看不到)肯定会得到一些东西。

从appBuilder.Use()语句中,我知道该服务肯定会被点击,它将导航到控制器。

我怎样才能找出错误或有人知道出了什么问题?

设置

public void OWINWebServerConfiguration(IAppBuilder appBuilder)
        {
            appBuilder.Use(async (environment, next) =>
            {
                //NOTE: Post will definitely hit this but I can't find the content of the message

                Debug.WriteLine(environment.Request.Uri);
                await next();
                Debug.WriteLine(environment.Response.StatusCode);
            });

            // Configure Web API for self-host. 
            HttpConfiguration config = new HttpConfiguration();

            // IMPORTANT - ENABLE UNITY TO TAKE CONTROL OVER DI
            config.DependencyResolver = new Helpers.UnityResolver(_unityContainer);


            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{content}",
                defaults: new { content = RouteParameter.Optional }
            );

            var cors = new EnableCorsAttribute(OWINConfig.AllowedAccessUrls, "*", "*");
        //config.EnableCors(new EnableCorsAttribute("*", "*", "GET, POST, OPTIONS, PUT, DELETE"));
        config.EnableCors(cors);

        appBuilder.UseWebApi(config);
        }

控制器

[HttpPost]
public HttpResponseMessage Post(FormCollection fc)
{

    //fc, will be null. Changing the signature means the controller will not be hit.
    HttpResponseMessage response;

   // if (value != null)
    //    System.Diagnostics.Debugger.Log(0, "ID:", value);

    response = Request.CreateResponse(HttpStatusCode.OK, "OK");

    return response;
}

截图

enter image description here

enter image description here

0 个答案:

没有答案