Код web сервиса:
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
namespace zzzz.Training.ASPNET.TEN
{
[WebService(Namespace = "http://TEN.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TENService : System.Web.Services.WebService
{
public TENService():base(){ }
[WebMethod]
public DataTable GetCategories()
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["TENDBConnectionString"].ConnectionString);
SqlCommand myCommand = new SqlCommand("GetCategories", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
SqlDataAdapter myDataAdapter = new SqlDataAdapter(myCommand.CommandText,myConnection);
DataTable myTable = new DataTable("Categories");
myDataAdapter.Fill(myTable);
myConnection.Close();
return myTable;
}
}
}
Код клиента:
using System;
using System.Data;
using TENServiceRef;
namespace Epam.Training.ASPNET.TEN
{
public partial class MasterPage : System.Web.UI.MasterPage
{
public MasterPage()
{
Load += new EventHandler(Page_Load);
}
protected void Page_Load(object sender, EventArgs e)
{
TENService srv = new TENService();
DataTable dt = srv .GetCategories();
}
}
}
В итоге — ошибка компиляции:
Cannot implicitly convert type 'TENServiceRef.GetCategoriesResponseGetCategoriesResult' to 'System.Data.DataTable'
Пробовал сгенерировать утилитой wsdl код прокси-класса, вот что получается (часть кода опущена):
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="TENServiceSoap", Namespace="http://TEN.org/")]
public partial class TENService : System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback GetCategoriesOperationCompleted;
/// <remarks/>
public TENService() {
this.Url = "http://localhost:4949/TENWebService/Service.asmx";
}
/// <remarks/>
public event GetCategoriesCompletedEventHandler GetCategoriesCompleted;
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://TEN.org/GetCategories", RequestNamespace="http://TEN.org/", ResponseNamespace="http://TEN.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public GetCategoriesResponseGetCategoriesResult GetCategories() {
object[] results = this.Invoke("GetCategories", new object[0]);
return ((GetCategoriesResponseGetCategoriesResult)(results[0]));
}
//...
}
//...
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class GetCategoriesResponseGetCategoriesResult {
private System.Xml.XmlElement[] anyField;
private System.Xml.XmlElement any1Field;
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
public System.Xml.XmlElement[] Any {
get {
return this.anyField;
}
set {
this.anyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAnyElementAttribute(Order=1)]
public System.Xml.XmlElement Any1 {
get {
return this.any1Field;
}
set {
this.any1Field = value;
}
}
}
//...
Вопрос: как нормально передать DataTable через веб-сервис?
как выходной параметр
Есть многое на свете, друг Гораций, что непонятно нашим мудрецам.
данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение
Ещё попробуй своим способом, но замени DataTable на DataSet. У меня нормально проходило вот как:
[WebMethod()]
public DataSet НазваниеФункции(параметры)
{
код
}
Есть многое на свете, друг Гораций, что непонятно нашим мудрецам.
данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение
Нормально с DataSet работает, в обоих дотнетах. Ищи кривизну в своём коде.
--
Абыpвалг! — сказал Linux после pyсификации
данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение