Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在Web API中为InstanceContextMode使用wcf ServiceBehavior属性?_Asp.net_Wcf_.net 4.5_Asp.net Web Api_Asp.net Web Api2 - Fatal编程技术网

Asp.net 如何在Web API中为InstanceContextMode使用wcf ServiceBehavior属性?

Asp.net 如何在Web API中为InstanceContextMode使用wcf ServiceBehavior属性?,asp.net,wcf,.net-4.5,asp.net-web-api,asp.net-web-api2,Asp.net,Wcf,.net 4.5,Asp.net Web Api,Asp.net Web Api2,如何在Web API 2项目中使用ServiceBehaviorAttribute在每个请求上创建和回收实例上下文对象?我试图通过在web.config中进行配置来以传统方式进行设置,但没有成功。我想我可能需要设置自定义属性,因此任何建议/想法都将受到欢迎 [ServiceBehaviorAttribute(InstanceContextMode = InstanceContextMode.PerCall)] 我不熟悉Web API,因此对它没有太多的了解。ServiceBehavior

如何在Web API 2项目中使用ServiceBehaviorAttribute在每个请求上创建和回收实例上下文对象?我试图通过在web.config中进行配置来以传统方式进行设置,但没有成功。我想我可能需要设置自定义属性,因此任何建议/想法都将受到欢迎

  [ServiceBehaviorAttribute(InstanceContextMode = InstanceContextMode.PerCall)] 

我不熟悉Web API,因此对它没有太多的了解。

ServiceBehaviorAttribute位于System.ServiceModel命名空间中,专门用于
WCF
而不是Web API。下面的链接似乎解决了您的问题:

当Web API在WCF上运行时,该属性可能会起作用,而ASP.NET Web API 2肯定不会起作用。默认情况下,后者会根据每个请求创建控制器的实例。那么,您使用的是Web API吗?如果是,是哪个版本?