0
Answer

Urgent help: the input stream is not a valid binary format, System.Runtime.Serialization.SerializationException

Melisa Ng

Melisa Ng

16y
12.9k
1

Our project uses the remoting as the distribution solution.

Client: Web Server (IIS 6)

Web Config is:

<system.runtime.remoting>

    <application>

      <channels>

        <channel ref="http">

          <clientProviders>

            <provider type="NCS.IConnect.ApplicationContexts.Remoting.Channels.ContextTransferClientSinkProvider, NCS.IConnect.ApplicationContexts"/>

            <formatter ref="binary"/>                              

                        </clientProviders>

        </channel>

      </channels>

    </application>

  </system.runtime.remoting>

Client source code like this:

Get object code via URL[RemotingProxyBase.cs]

    [EnvironmentPermission(SecurityAction.LinkDemand, Unrestricted=true)]

    protected virtual T GetObject(string url)

    {

        string proxyUrl = this.GetProxyUrl(url);

        return (T) Activator.GetObject(typeof(T), proxyUrl);

    }

 

    protected virtual string GetProxyUrl(string url)

    {

        return UrlHelper.GetRemotingUrl(url);

    }

 

Invoke the get method[CalculatorServiceProxy.cs]

…………………

 

        private const string RemoteUri = "http://localhost/RemotingServices/xxxx.rem";//It should be get from the config file, here is only for demo

 

        #region ICalculator Members

 

        public double Add(double x, double y)

        {

            return this.GetObject(RemoteUri).Add(x, y);

        }

 

        #endregion

    }

…………

Client code[Client.cs]

………………

CalculatorServiceProxy proxy = new CalculatorServiceProxy();

Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, proxy.Add(1, 2));

…………

Application Server:  IIS Host(Remoting)

  <system.runtime.remoting>

    <application>

      <channels>

        <channel ref="http">

          <serverProviders>

            <formatter ref="binary" />

            <provider type="xxxx.ApplicationContexts.Remoting.Channels.ContextTransferServerSinkProvider, xxxx.ApplicationContexts, Version=3.0.10919.0, Culture=neutral, PublicKeyToken=null" />

          </serverProviders>

        </channel>

      </channels>

      <service>

        <wellknown type="xxxx.CodeTableRemotingService,xxxx.CodeTable" objectUri="xxxx.rem" mode="SingleCall" />

      </service>

    </application>

  </system.runtime.remoting>

Service Source Code like this:

    public class CalculatorService:MarshalByRefObject, ICalculator

    {

        #region ICalculator Members

 

        public double Add(double x, double y)

        {           

            return x + y;

        }

 

        #endregion

    }

We have faced 2 critical  issue.

1)    When we test the remoting server via in the IE brower(http://localhost/RemotingServices/Calcualtor.rem?wsdl):

It always get the below exception(whether or not the server remoting use the binary or soap format):

System.ArgumentNullException: No message was deserialized prior to calling the DispatchChannelSink.
Parameter name: requestMsg
   at System.Runtime.Remoting.Channels.DispatchChannelSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.Http.HttpHandlerTransportSink.HandleRequest(HttpContext context)
   at System.Runtime.Remoting.Channels.Http.HttpRemotingHandler.InternalProcessRequest(HttpContext context) 
 
When I run the client programme,
If the server use the soap format, it is working ok; if server use the binary format, it can’t working ok, and show the same exception with the above.

 

2)    In our production, our solution is the same architecture with the above description, It always throw the below exception in the web server log. We have tried a lot of time find the root cause, from some article, the means the remoting server occurs the exception and the web server can’t deserialize it into normal http

Format.

----------------------------------------

Timestamp: 29/11/2008 04:53 PM

Message:  System.Runtime.Serialization.SerializationException: The input stream is not a valid binary format. The starting contents (in bytes) are: 3C-3F-78-6D-6C-20-76-65-72-73-69-6F-6E-3D-22-31-2E ...

 

Server stack trace:

   at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Read(__BinaryParser input)

   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadSerializationHeaderRecord()

   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()

   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

   at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)

   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

 

Exception rethrown at [0]:

   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

   at NCS.IConnect.SessionManagement.ISessionRemotingService.RefreshUserSession(String userName, String sessionId, Int32 accountTimeOut)

   at NCS.IConnect.SessionManagement.RemotingSessionProvider.RefreshUserSession(String userName, String sessionId, Int32 accountTimeOut)

   at NCS.IConnect.SessionManagement.Web.SessionManager.RefreshCurrentUserSession()

   at NCS.Customs.Framework.WebUI.CustomsPageBase.OnInit(EventArgs e) in e:\eCustoms\Migration\MigrationBaseVersion_7687\WebUI\CustomsPageBase.cs:line 103

   at System.Web.UI.Control.InitRecursive(Control namingContainer)

   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Extended Properties: AuthenticationType - Forms IdentityName - 00268771 IsAuthenticated - True

Machine:  ECPDCWEB01

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Has anybody encountered the error? Is there any resolution to fix the issue?


Any help would be appreciated. Thanks in advance.