2013-07-23 41 views
1

我們最近更改了硬件配置,並開始通過我們的Web服務發送大文件時遇到問題。在隨機的場合,我們發送的肥皂信息在接收端被破壞。收到的消息內容與發送的消息內容不同。我寫了一個小測試程序,能夠在小範圍內重現我們的問題。大型文件上的.NET隨機SOAP消息損壞

程序在接收端有一個WCF webservice,發送端有一個windows窗體應用程序。表單應用程序向WCF Web服務發送一個大字符串。 兩者都使用wshttpbinding進行通信。 WCF webservice安裝在Windows Server 2008 R2 x64上的IIS7上。 Windows窗體應用程序運行在使用VMWare(5.0)虛擬化的Windows Server 2012標準版上。

例外嘗試讀取XML時拋出總是這樣(XML腐敗):

System.Xml.XmlException: 'B' is an unexpected token. Expecting white space. Line 1, position 5820605. 
    at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) 
    at System.Xml.XmlTextReaderImpl.ParseAttributes() 
    at System.Xml.XmlTextReaderImpl.ParseElement() 
    at System.Xml.XmlTextReaderImpl.ParseElementContent() 
    at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) 
    at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) 
    at System.Xml.XmlDocument.Load(XmlReader reader) 
    at System.Xml.XmlDocument.LoadXml(String xml) 
    at WCFReciever.Service1.SendXml(String xml) in c:\xxxxxxx\visual studio 2010\Projects\WCFReciever\WCFReciever\Service1.svc.cs:line 22 

NOTES

  • 當我們運行在不同的服務器 在Windows窗體應用程序(Windows服務器2008 R2 x64,物理安裝),則不會再發生問題 。由於腐敗是隨機的,因此我們排除了任何配置,綁定,請求限制問題 。
  • basicHttpBinding的示出了同樣的問題
  • 該軟件運行無故障3年
  • 對於不同的內容,會出現問題(字節[] +/- 10 MB,字符串> 10MB,XML 45 MB等)
  • 我們一直在調試這個問題好幾天沒有任何結果

提前感謝!

代碼段爲測試程序

表單應用程序

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       Result.Text = string.Empty; 

       var client = new WCFReciever.Service1Client(); 

       //some large file, in this case a xml structured file, 44MB 
       var osil = File.ReadAllText("test.osil"); 

       if (client.SendXml(osil)) 
       { 
        Result.Text += "success"; 
       } 
       else 
       { 
        Result.Text += "failed"; 
       }        
      } 
      catch (Exception ex) 
      { 
       Result.Text += ex.ToString(); 
      } 
     } 
    } 
} 

WCF Recvier

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Web; 
using System.Text; 
using System.Xml; 
using System.IO; 

namespace WCFReciever 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. 
    public class Service1 : IService1 
    { 
     public bool SendXml(string xml) 
     { 
      try 
      {     
       XmlDocument doc = new XmlDocument(); 
       doc.LoadXml(xml);     
       return true; 
      } 
      catch (Exception e) 
      {     
       return false; 
      } 
     }    
    } 

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. 
    [ServiceContract] 
    public interface IService1 
    { 
     [OperationContract] 
     bool SendXml(string xml); 
    } 
} 

綁定配置

 <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/>   
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="wsHttpBinding1" closeTimeout="00:10:00" 
     openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" textEncoding="utf-8" 
     useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" 
       realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <services> 
     <service name="WCFReciever.Service1"> 
     <endpoint contract="WCFReciever.IService1" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding1"/> 
     </service> 
     </services> 
    </system.serviceModel> 

回答

0

問題解決了。 VMWare默認安裝的網絡適配器與服務器2012之間存在問題。使用不同的網絡適配器似乎已解決該問題。