web service System.Xml.Linq.XDeclaration cannot be serialized because not have a parameterless constructor.

I have a web serivice that does this (for debugging)

    <WebMethod()> _
    Public Function FileList(ByVal curuser As String) As String
        xmlfilelist = "<?xml version=""1.0"" encoding=""utf-8"" ?><test>my stuff</test>"
        Return (xmlfilelist)
    End Function


But the consumer gets:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <FileListResponse xmlns="http://tempuri.org/">
      <FileListResult>&lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;test&gt;my stuff&lt;/test&gt;</FileListResult>
    </FileListResponse>
  </soap:Body>
</soap:Envelope>

So i changed to:

    <WebMethod()> _
    Public Function FileList(ByVal curuser As String) As XDocument

        Dim flvFilelist() As String = IO.Directory.GetFiles("C:\Program Files (x86)\Adobe\Flash Media Server 3.5\applications\audiotest\streams\_definst_", "*.flv")
        Dim xmlfilelist As String = ""
        If flvFilelist.Length > 0 Then
            xmlfilelist = "<?xml version=""1.0"" encoding=""utf-8"" ?>" + vbCrLf + "<filelist>" + vbCrLf
            For i As Integer = 0 To flvFilelist.Length - 1
                xmlfilelist += "<file>filename</file>".Replace("filename", IO.Path.GetFileName(flvFilelist(i))) + vbCrLf
            Next
            xmlfilelist += "</filelist>"
            'xmlfilelist = Server.UrlDecode(xmlfilelist)
        End If
        'Return Server.UrlEncode(xmlfilelist)

        'xmlfilelist = "<?xml version=""1.0"" encoding=""utf-8"" ?><test>my stuff</test>"
        Dim srcTree As XDocument = XDocument.Parse(xmlfilelist)






        Return (srcTree)
    End Function


But now i get an error

System.Xml.Linq.XDeclaration cannot be serialized because it does not have a parameterless constructor.


How can i keep the body of the soap message from bein url encoded in .net?
nphoenixAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
Any serializable class need a default constructor.
You cannot avoid encoding, otherwise you will end up with illegal xml construct.

Alternative 1: You can send the file as binary, check:
http://www.zdnetasia.com/create-a-simple-file-transfer-web-service-with-net-39251815.htm

Alternative 2: You can send your list as string[]  instead of string.

My question to you is why do you need xml declaration if you can send the info as string array.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SriVaddadiCommented:
If you want to send xml, then use return XmlNode object
0
SriVaddadiCommented:
Hi nphoenix, Did you check on the solutions?
0
nphoenixAuthor Commented:
(You must provide a reason for closing the question when assigning a grade of "B"):  i was in over my head and ended up takeing quite soem tiem to convert to string
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.