• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2414
  • Last Modified:

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?
0
nphoenix
Asked:
nphoenix
  • 2
1 Solution
 
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
 
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now