[Mono-dev] Problem with WCF and IEnumerable as return type

Chakotey STME chakoteystme at gmail.com
Tue Nov 30 07:42:04 EST 2010


Hello,

I have a problem with WCF.

If I have this service contract:

<ServiceContract()> _
Public Interface IHelloService
    <OperationContract()> _
    Function Greet(ByVal name As String) As IEnumerable(Of Objekt)
End Interface

This Service:
Imports System.ServiceModel

Module Module1
    Sub Main()
        Dim host As ServiceHost = New ServiceHost(GetType(HelloService))
        host.Open()
    End Sub
End Module

The implementaion of HelloService of the Service:
Imports Contracts

Public Class HelloService
    Implements IHelloService
    Public Function Greet(ByVal name As String) As IEnumerable(Of
Objekt) Implements IHelloService.Greet
        Dim myObjekt As Objekt = New Objekt
        Dim myObjekt2 As Objekt = New Objekt

        myObjekt.text = "Hallo"
        myObjekt.number = 3 + name.Length

       Dim list As IList(Of Objekt) = New List(Of Objekt)

        list.Add(myObjekt)
        list.Add(myObjekt2)

        Return list

    End Function

End Class


And this client:
Imports System.ServiceModel
Imports Contracts

Module Module1

    Sub Main()
        Dim binding = New BasicHttpBinding()
        Dim address = New EndpointAddress("http://192.168.100.110:8080")
        Dim client = New HelloClient(binding, address)
        Dim myObjekt = client.Greet("name")

        Console.ReadLine()
    End Sub
End Module

The implementation of HelloService from the client:

Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Runtime.Serialization
Imports Contracts

Public Class HelloClient
    Inherits ClientBase(Of IHelloService)
    Implements IHelloService
    Public Sub New(ByVal binding As Binding, ByVal address As EndpointAddress)
        MyBase.New(binding, address)
    End Sub

    Public Function Greet(ByVal name As String) As IEnumerable(Of
Objekt) Implements IHelloService.Greet
        Return Channel.Greet(name)
    End Function
End Class


I execute the service and execute the client.
I get this Exception:
Exception Non-empty prefix must be mapped to non-empty namespace URI.
 at System.Xml.XmlTextWriter.WriteEndAttribute () [0x00000] in
<filename unknown>:0
  at System.Xml.XmlSimpleDictionaryWriter.WriteEndAttribute ()
[0x00000] in <filename unknown>:0
  at System.Xml.XmlWriter.WriteAttributeString (System.String prefix,
System.String localName, System.String ns, System.String value)
[0x00000] in <filename unknown>:0
  at System.Xml.XmlDictionaryWriter.WriteXmlnsAttribute (System.String
prefix, System.String namespaceUri) [0x00000] in <filename unknown>:0
  at System.Runtime.Serialization.DataContractSerializer.WriteStartObject
(System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x00000]
in <filename unknown>:0
  at System.Runtime.Serialization.XmlObjectSerializer.WriteObject
(System.Xml.XmlDictionaryWriter writer, System.Object graph) [0x00000]
in <filename unknown>:0
  at System.ServiceModel.Dispatcher.DataContractMessagesFormatter+DataContractBodyWriter.WriteMessagePart
(System.Xml.XmlDictionaryWriter writer,
System.ServiceModel.Description.MessageBodyDescription desc,
System.ServiceModel.Description.MessagePartDescription partDesc,
System.Object obj) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.DataContractMessagesFormatter+DataContractBodyWriter.OnWriteBodyContents
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.BodyWriter.WriteBodyContents
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.SimpleMessage.OnWriteBodyContents
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.Message.WriteBodyContents
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.Message.WriteBody
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.Message.OnWriteMessage
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.Message.WriteMessage
(System.Xml.XmlDictionaryWriter writer) [0x00000] in <filename
unknown>:0
  at System.ServiceModel.Channels.TextMessageEncoder.WriteMessage
(System.ServiceModel.Channels.Message message, System.IO.Stream
stream) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.HttpRequestContext.ProcessReply
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]
in <filename unknown>:0
  at System.ServiceModel.Channels.HttpRequestContextBase.Reply
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]
in <filename unknown>:0
  at System.ServiceModel.Dispatcher.MessageProcessingContext.Reply
(Boolean useTimeout) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.OperationInvokerHandler.Reply
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc, Boolean
useTimeout) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)
[0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)
[0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)
[0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)
[0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)
[0x00000] in <filename unknown>:0
  at System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)
[0x00000] in <filename unknown>:0



If I change the return type in the contracts, the client and the
service, from IEnumerable(of objekt) to IList(Of objekt) it works!

Why can't I use IEnumerable as return type?

thanks

chakoteystme


More information about the Mono-devel-list mailing list