tags:

views:

46

answers:

1

I am trying to develop a WCF REST app as explained in http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/04640a45-1a37-4722-8ed7-9f75c155dc14 (which serves both XML and JSON at the same time).

the error is in the return statement of the following code:

Public Function SerializeReply(ByVal messageVersion As System.ServiceModel.Channels.MessageVersion, ByVal parameters() As Object, ByVal result As Object) As System.ServiceModel.Channels.Message Implements System.ServiceModel.Dispatcher.IDispatchMessageFormatter.SerializeReply
    Dim formatter As IDispatchMessageFormatter = Me.xmlFormatter
    If OperationContext.Current.OutgoingMessageProperties.ContainsKey(WebBodyFormatMessageProperty.Name) Then
        Dim webBody As WebBodyFormatMessageProperty = DirectCast(OperationContext.Current.OutgoingMessageProperties(WebBodyFormatMessageProperty.Name), WebBodyFormatMessageProperty)
        If webBody IsNot Nothing AndAlso webBody.Format = WebContentFormat.Json Then
            formatter = Me.jsonFormatter
        End If
    End If

    Return formatter.SerializeReply(messageVersion, parameters, result)
End Function

It gives the error as "The given key was not present in the dictionary."

further going deeper the stack trace looks like the following:

Encountered unexpected namespace 'http://schemas.microsoft.com/ws/2005/05/envelope/none'. The namespace must be empty.
Parameter name: ns    at System.Runtime.Serialization.Json.XmlJsonWriter.WriteStartElement(String prefix, String localName, String ns)
   at System.ServiceModel.Channels.MessageFault.WriteTo12Driver(XmlDictionaryWriter writer, EnvelopeVersion version)
   at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
   at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
   at System.ServiceModel.Channels.JsonMessageEncoderFactory.JsonMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
   at System.ServiceModel.Channels.WebMessageEncoderFactory.WebMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
   at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
   at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc& rpc) 

Also the following:

The given key was not present in the dictionary.    at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at System.ServiceModel.Dispatcher.MultiplexingDispatchMessageFormatter.SerializeReply(MessageVersion messageVersion, Object[] parameters, Object result)
   at PersonifyWcfServiceLib.PersonifyReplyDispatchMessageFormatter.SerializeReply(MessageVersion messageVersion, Object[] parameters, Object result) in C:\PROJECTS\EBusiness\Current\Product\Production\WcfServices\PersonifyWcfServiceLib\ErrorHandlers\PersonifyReplyDispatchMessageFormatter .vb:line 28
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.SerializeOutputs(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)