Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I am trying to send a query to my local server and the server return xml fromat to the client

when I tryto run the server side I get this error
Quote:
Cannot serialize interface System.Collections.Generic.IEnumerable`1[[WebApplication1.ReturnValues, WebApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
cananybody help mein this issue?

this is my server side code:

C#
<blockquote class="quote"><div class="op">Quote:</div>using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Xml;
using System.Xml.Linq;

namespace WebApplication1
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class MyWebService : System.Web.Services.WebService
    {
        
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        public IEnumerable<ReturnValues> MyService(String vinValue)
        {
            LinqSqlDataContext db = new LinqSqlDataContext();
            var reportdata = from f in db.ff
                             from gin db.gg
                             from h in db.hh
                             where f.first== vinValue 
                             select new XElement("flash",
                                 new XElement("first", f.first),
                                 new XElement("second", g.second)
                                 );
            var reportXml = new XElement("FlashList", reportdata);
            reportXml.Save("file.xml");


            string uri = Uri.EscapeUriString(vinValue);
            string url = FormatUrl(uri);
            XDocument xdoc = XDocument.Load(url);

            IEnumerable<ReturnValues> results =
                            from info in xdoc.Descendants("VIN")
                            select new ReturnValues
                            {
                                first= info.Element("first").Value,
                                second= info.Element("second").Value,
                                
                            };

            return results;
        }

        string FormatUrl(string vinVal)
        {
            return "http://localhost:11936/MyWebService.asmx&VIN="+vinVal;
        }        
    }
}



and also another class:

C#
namespace WebApplication1
{
    public class ReturnValues
    {
        public string first{ get; set; }
        public string second{ get; set; }

    }
}




AND in client side

C#
<pre lang="xml"><blockquote class="quote"><div class="op">Quote:</div>namespace FlashListByVinLadan
{
    public partial class MainWindow : Window
    {
        string vinValue;


        public MainWindow()
        {
            InitializeComponent();
        }

        private void FrameLoad_Activated(object sender, EventArgs e)
        {

        }



        private void btnGo_Click(object sender, RoutedEventArgs e)
        {
            localhost.MyWebService w = new localhost.MyWebService();
            IEnumerable<ReturnValues> req = w.MyService(vinValue);
}


Posted
Comments
Eng.Yahya92 18-Apr-15 4:54am    
not familiar with the way you are trying to use to connect beween client and server, However I have a server client dll which can do this for you without problems (I hope )

1 solution

The XmlSerializer won't serialize interfaces.
Your method is returning an interface, so this is what it's complaining about.
Try returning a List instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900