来自响应的不完整消息

时间:2014-07-30 05:39:49

标签: wcf app-config

我有一个wcf服务,我试图从其他客户端调用它,但我作为回复得到的响应是不完整的。它从

停止
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {

        if (Log.IsDebugEnabled)
        {
            Log.Debug("VisService SOAP Response >>>");
            //create a copy of the response for logging purpose
            MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
            reply = buffer.CreateMessage();
            //log the copy to avoid removal of the actual response object
            System.ServiceModel.Channels.Message replyCopy = buffer.CreateMessage();
            MemoryStream ms = new MemoryStream();
            System.Xml.XmlDictionaryWriter writer = System.Xml.XmlDictionaryWriter.CreateTextWriter(ms);
            replyCopy.WriteMessage(writer);
            //move the position of the cursor to the begining to
            //read the entire message from start
            ms.Position = 0;
            string visServiceSOAPResponse = new StreamReader(ms, Encoding.UTF8).ReadLine();
            Log.Debug(visServiceSOAPResponse);
            //For displaying the message in the mail confirmation box
            SaveResponseToLog("\nVisService SOAP Response >>>\n" + visServiceSOAPResponse);
        }   
    }

    //This function logs the SOAP 
    //request in the application log file
    public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
    {
        if (Log.IsDebugEnabled)
        {
            string visServiceSOAPRequest = request.ToString();
            Log.Debug("VisService SOAP Request >>>");
            Log.Debug(visServiceSOAPRequest);
            //For displaying the message in the mail confirmation box
            SaveResponseToLog("\nVisService SOAP Request >>>\n" +     visServiceSOAPRequest);
        }
        return null;
    }        
}

并且wcf的响应仅在“... xmlns =”

之前

1 个答案:

答案 0 :(得分:0)

您的日志写入功能有问题。请完全废弃它。如果要将文本附加到文件,请使用AppendAllText

此外,您似乎只阅读响应的第一行。在将其写入文件之前,您需要先读取整个响应。

编辑:

您的日志功能有太多的错误和奇怪的事情来实际修复它。替换为:

private void SaveResponseToLog(string msg)
{
  System.IO.File.AppendAllText(filename, msg, Encoding.UTF8);
}