客户端服务器请求发送和接收问题 [英] client server request send and receive problem
问题描述
嗨
我正在尝试向我的本地服务器发送查询,服务器将xml返回给客户端
当我尝试运行服务器端时我收到此错误
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
无法序列化接口System.Collections。 Generic.IEnumerable`1 [[WebApplication1.ReturnValues,WebApplication1,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null]]。
cananybody帮我解决这个问题?
这是我的服务器端代码:
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:
<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:
namespace WebApplication1
{
public class ReturnValues
{
public string first{ get; set; }
public string second{ get; set; }
}
}
AND在客户端
AND in client side
<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);
}
推荐答案
XmlSerializer
不会序列化接口。
你的方法正在返回一个接口,所以这就是它所抱怨的。
请尝试返回列表
。
这篇关于客户端服务器请求发送和接收问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!