2017-08-16 17 views
1

我创建了一个Web服务,即使它连接并从响应方法提取数据,它被挂了这个错误:System.ServiceModel.FaultException`1:'Session已关闭。请重新登录(C#Web服务)

System.ServiceModel.FaultException`1: 'Session was closed. Please, login again'

enter image description here

当我跑了一步,进入调试它的这部分代码用于设置它关闭:

public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) 
    { 
     //Get the HttpRequestMessage property from the message 
     HttpRequestMessageProperty httpreq = null; 

     try 
     { 
      httpreq = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; 
     } 
     catch //(Exception exc) 
     { 
     } 

     if (httpreq == null) 
     { 
      httpreq = new HttpRequestMessageProperty(); 
      request.Properties.Add(HttpRequestMessageProperty.Name, httpreq); 
     } 

     byte[] authbytes = Encoding.UTF8.GetBytes(string.Concat(Username, ":", Password)); 
     string base64 = Convert.ToBase64String(authbytes); 
     string authorization = string.Concat("Basic ", base64); 

     httpreq.Headers["Authorization"] = authorization; 

     return null; 
    } 

有谁知道如何杀死一个C#控制台应用程序会话,以确保这不继续发生?

谢谢!

+0

我打算删除图片,因为它没有在问题中添加任何内容,然后我注意到图片中部分模糊的代码未出现在代码中。你能澄清你的错误在哪里吗? – stuartd

+0

它在上面粘贴的代码中。本质上它在返回null之后跳转;抓到了。实际上我没有任何“错误”,因为我已经开始使用这项服务了,我只是不理解这种行为,并且看到有人能够帮助我更好地理解和/或解决这个问题。 – darksideguy

回答

0

没关系问题。此问题即将发生,因为我的代码依赖于另一个Web会话来首先建立连接。这就是为什么我得到“会话被关闭”的错误,因为我在不打开其他服务的情况下运行项目。

谢谢。