为什么WCF的OperationContext.Current的值不是这个OperationContextScope安装的OperationContext值错误,没有任何代码更改?
本周,在没有任何代码更改的情况下,我们的旧版 WCF Web 服务开始在我们的 API 管理系统上抛出“OperationContext.Current 的值不是此 OperationContextScope 安装的 OperationContext 值”错误。
我们检查了已安装的 .net 版本 (.net 4.5.1) 和其他安装。一切看起来都不错。 当我们尝试在本地计算机上调试时,我们无法重现相同的错误。
我的相关代码部分如下:
internal static T InvokeService<T>(this CalculatorClient client, Func<CalculatorClient, T> method)
{
if (client.ClientCredentials.UserName.UserName == null)
{
client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["APIMANAGEMENT_User"];
client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["APIMANAGEMENT_Pwd"];
}
T result;
using (new OperationContextScope(client.InnerChannel))
{
string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(ConfigurationManager.AppSettings["APIMANAGEMENT_User"] + ":" + ConfigurationManager.AppSettings["APIMANAGEMENT_Pwd"]));
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers["Authorization"] = auth;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
result = method.Invoke(client);
}
return result;
}
您知道它为什么失败吗?
This week without any code change, our legacy WCF web service started to throw "The value of OperationContext.Current is not the OperationContext value installed by this OperationContextScope" error on our API management system.
We have checked installed .net version (.net 4.5.1) and other installations. All seems OK.
When we have tried to debug on local computer, we can not reproduce same error.
My related code part is below:
internal static T InvokeService<T>(this CalculatorClient client, Func<CalculatorClient, T> method)
{
if (client.ClientCredentials.UserName.UserName == null)
{
client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["APIMANAGEMENT_User"];
client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["APIMANAGEMENT_Pwd"];
}
T result;
using (new OperationContextScope(client.InnerChannel))
{
string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(ConfigurationManager.AppSettings["APIMANAGEMENT_User"] + ":" + ConfigurationManager.AppSettings["APIMANAGEMENT_Pwd"]));
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers["Authorization"] = auth;
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
result = method.Invoke(client);
}
return result;
}
Do you have any idea about why it is failing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论