Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Read WebService List<> data

Reply
Thread Tools

Read WebService List<> data

 
 
Peter
Guest
Posts: n/a
 
      10-09-2008
I have a WebService which returns a List of RunningReport class
How do I read this XML data on the client side. How do I convert
List<RunningReport> from the WebService side to List<RunningReport> on the
client side

I have tried the following:

List<RunningReport> reportList = null;

localhost.ReportService localrs = new localhost.ReportService();
localrs.Url = GetServiceURL();
reportList = localrs.RunningReports();


but I am getting the following error

Error 67 Cannot implicitly convert type 'localhost.RunningReport[]' to
'System.Collections.Generic.List<Reports.Modules.R unningJobs.RunningReport>


Thank You

Peter


//////////////// Heres' the XML data from the WebService
///////////////////////////////////

<?xml version="1.0" encoding="utf-8" ?>
ArrayOfRunningReport xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlns="http://wsinc.com/webservices/">
<RunningReport>
<ReportID>0</ReportID>
<CreatedBy>12</CreatedBy>
<ItemId>1</ItemId>
<OutputType>PDF</OutputType>
</RunningReport>
<RunningReport>
<ReportID>0</ReportID>
<CreatedBy>12</CreatedBy>
<ItemId>2</ItemId>
<OutputType>PDF</OutputType>
</RunningReport>
</ArrayOfRunningReport>


///////////////////////////////////// Here's the class that the Webservice
is returning: ////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReportInfoLib
{
[Serializable]
public class RunningReport
{
private string _reportName;
private int _reportID;
private int _createdBy;
private string _discription;
private int _itemId;
private DocumentTypeEnum _outputType;
private string _printerName;
private string _trayName;
private string _emailList;
private List<ParameterNameValue> _pnv;

public string ReportName
{
get { return this._reportName; }
set { this._reportName = value; }
}

public int ReportID
{
get { return this._reportID; }
set { this._reportID = value; }
}

public int CreatedBy
{
get { return this._createdBy; }
set { this._createdBy = value; }
}

public string Discription
{
get { return this._discription; }
set { this._discription = value; }
}

public int ItemId
{
get { return this._itemId; }
set { this._itemId = value; }
}

public ReportInfoLib.DocumentTypeEnum OutputType
{
get { return this._outputType; }
set { this._outputType = value; }
}

public string PrinterName
{
get { return this._printerName; }
set { this._printerName = value; }
}

public string TrayName
{
get { return this._trayName; }
set { this._trayName = value; }
}

public string EmailList
{
get { return this._emailList; }
set { this._emailList = value; }
}

public
System.Collections.Generic.List<ReportInfoLib.Para meterNameValue> Pnv
{
get { return this._pnv; }
set { this._pnv = value; }
}
}
}


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      10-09-2008
"Peter" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have a WebService which returns a List of RunningReport class
> How do I read this XML data on the client side. How do I convert
> List<RunningReport> from the WebService side to List<RunningReport> on the
> client side


Sorry, it doesn't work this way.

The client has no idea what type the server is using. Remember that the
client could be running Java, in which case, it certainly doesn't know
anything about List<RunningReport>.

What the client _does_ know about is the XML Schema that it gets from the
WSDL file that it gets from the server when you use Add Web Reference. That
schema will have a section similar to this:

<xs:element name="ArrayOfRunningReport">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" type="RunningReport"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Notice the total lack of mention of List<T>.

Using ASMX web services (which you seem to be doing), that will always
translate into RunningReport[] on the client. If you were using WCF, you'd
be able to tell it to use List<T> instead. Since you're using the old stuff,
you'll have to fake it:

List<RunningReport> reportList ; //= null; Don't do this. The
default is null, besides, it gets overwritten

localhost.ReportService localrs = new localhost.ReportService();
localrs.Url = GetServiceURL();
RunningReports[] reportsArray = localrs.RunningReports();
reportList = new List<RunningReports>(reportsArray);

--
John Saunders | MVP - Connected System Developer


 
Reply With Quote
 
 
 
 
Peter
Guest
Posts: n/a
 
      10-10-2008

"John Saunders" <(E-Mail Removed)> wrote in message
news:OcpE$(E-Mail Removed)...
> "Peter" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I have a WebService which returns a List of RunningReport class
>> How do I read this XML data on the client side. How do I convert
>> List<RunningReport> from the WebService side to List<RunningReport> on
>> the client side

>
> Sorry, it doesn't work this way.
>
> The client has no idea what type the server is using. Remember that the
> client could be running Java, in which case, it certainly doesn't know
> anything about List<RunningReport>.
>
> What the client _does_ know about is the XML Schema that it gets from the
> WSDL file that it gets from the server when you use Add Web Reference.
> That schema will have a section similar to this:
>
> <xs:element name="ArrayOfRunningReport">
> <xs:complexType>
> <xs:sequence>
> <xs:element minOccurs="0" maxOccurs="unbounded" type="RunningReport"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> Notice the total lack of mention of List<T>.
>
> Using ASMX web services (which you seem to be doing), that will always
> translate into RunningReport[] on the client. If you were using WCF, you'd
> be able to tell it to use List<T> instead. Since you're using the old
> stuff, you'll have to fake it:
>
> List<RunningReport> reportList ; //= null; Don't do this. The
> default is null, besides, it gets overwritten
>
> localhost.ReportService localrs = new localhost.ReportService();
> localrs.Url = GetServiceURL();
> RunningReports[] reportsArray = localrs.RunningReports();
> reportList = new List<RunningReports>(reportsArray);
>
> --
> John Saunders | MVP - Connected System Developer
>
>


Thank You for your help!

This the following line does not work:
RunningReports[] reportsArray = localrs.RunningReports();

Cannot implicitly convert type 'localhost.RunningReport[]' to
'Reports.Modules.RunningJobs.RunningReport[]'


 
Reply With Quote
 
Steven Cheng
Guest
Posts: n/a
 
      10-10-2008
Hi Peter,

The problem you encountered, is caused by XML webservice does not expose
implement details to client(only expose WSDL service description) for
interop purpose. Therefore, for any custom types used in webservice, by
default the client-side will generate a light weight delegate class to
represent it. That's why, for your scenario, it reports the following error:

================
Cannot implicitly convert type 'localhost.RunningReport[]' to
'Reports.Modules.RunningJobs.RunningReport[]'
===============

here the "localhost.RunningReport" type is generated by the webservice
client proxy(add webreference), while
"Reports.Modules.RunningJobs.RunningReport" is your own type(the type used
at server-side).

Currently one way to overcome this problem is manually modify the
auto-generated webservice proxy's source code. You can change the return
type from the "localhost.RunningReport[]" to
"Reports.Modules.RunningJobs.RunningReport[]". The drawback of this is
when you update the webservice refefence, your change will be overwritten.
To avoid this, you can add a partial class file for the webservice clienet
proxy class, and add a new method (the same signature and attributes as the
original webmethod), and chang the return type to the one you want.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Peter" <(E-Mail Removed)>
>References: <(E-Mail Removed)>

<OcpE$(E-Mail Removed)>
>Subject: Re: Read WebService List<> data
>Date: Thu, 9 Oct 2008 21:19:42 -0500


>
>
>"John Saunders" <(E-Mail Removed)> wrote in message
>news:OcpE$(E-Mail Removed)...
>> "Peter" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> I have a WebService which returns a List of RunningReport class
>>> How do I read this XML data on the client side. How do I convert
>>> List<RunningReport> from the WebService side to List<RunningReport> on
>>> the client side

>>
>> Sorry, it doesn't work this way.
>>
>> The client has no idea what type the server is using. Remember that the
>> client could be running Java, in which case, it certainly doesn't know
>> anything about List<RunningReport>.
>>
>> What the client _does_ know about is the XML Schema that it gets from

the
>> WSDL file that it gets from the server when you use Add Web Reference.
>> That schema will have a section similar to this:
>>
>> <xs:element name="ArrayOfRunningReport">
>> <xs:complexType>
>> <xs:sequence>
>> <xs:element minOccurs="0" maxOccurs="unbounded" type="RunningReport"/>
>> </xs:sequence>
>> </xs:complexType>
>> </xs:element>
>>
>> Notice the total lack of mention of List<T>.
>>
>> Using ASMX web services (which you seem to be doing), that will always
>> translate into RunningReport[] on the client. If you were using WCF,

you'd
>> be able to tell it to use List<T> instead. Since you're using the old
>> stuff, you'll have to fake it:
>>
>> List<RunningReport> reportList ; //= null; Don't do this. The
>> default is null, besides, it gets overwritten
>>
>> localhost.ReportService localrs = new localhost.ReportService();
>> localrs.Url = GetServiceURL();
>> RunningReports[] reportsArray = localrs.RunningReports();
>> reportList = new List<RunningReports>(reportsArray);
>>
>> --
>> John Saunders | MVP - Connected System Developer
>>
>>

>
>Thank You for your help!
>
>This the following line does not work:
>RunningReports[] reportsArray = localrs.RunningReports();
>
>Cannot implicitly convert type 'localhost.RunningReport[]' to
>'Reports.Modules.RunningJobs.RunningReport[]'
>
>
>


 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      10-10-2008
""Steven Cheng"" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Peter,
>
> The problem you encountered, is caused by XML webservice does not expose
> implement details to client(only expose WSDL service description) for
> interop purpose. Therefore, for any custom types used in webservice, by
> default the client-side will generate a light weight delegate class to
> represent it. That's why, for your scenario, it reports the following
> error:
>
> ================
> Cannot implicitly convert type 'localhost.RunningReport[]' to
> 'Reports.Modules.RunningJobs.RunningReport[]'
> ===============
>
> here the "localhost.RunningReport" type is generated by the webservice
> client proxy(add webreference), while
> "Reports.Modules.RunningJobs.RunningReport" is your own type(the type used
> at server-side).
>
> Currently one way to overcome this problem is manually modify the
> auto-generated webservice proxy's source code. You can change the return
> type from the "localhost.RunningReport[]" to
> "Reports.Modules.RunningJobs.RunningReport[]". The drawback of this is
> when you update the webservice refefence, your change will be overwritten.
> To avoid this, you can add a partial class file for the webservice clienet
> proxy class, and add a new method (the same signature and attributes as
> the
> original webmethod), and chang the return type to the one you want.


As Steven has said, this will not work, as it will be overwritten every time
you update your web reference.

The correct solution is simply to use:

localhost.RunningReports[] reportsArray = localrs.RunningReports();
--
John Saunders | MVP - Connected System Developer


 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      10-10-2008

"John Saunders" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> ""Steven Cheng"" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi Peter,
>>
>> The problem you encountered, is caused by XML webservice does not expose
>> implement details to client(only expose WSDL service description) for
>> interop purpose. Therefore, for any custom types used in webservice, by
>> default the client-side will generate a light weight delegate class to
>> represent it. That's why, for your scenario, it reports the following
>> error:
>>
>> ================
>> Cannot implicitly convert type 'localhost.RunningReport[]' to
>> 'Reports.Modules.RunningJobs.RunningReport[]'
>> ===============
>>
>> here the "localhost.RunningReport" type is generated by the webservice
>> client proxy(add webreference), while
>> "Reports.Modules.RunningJobs.RunningReport" is your own type(the type
>> used
>> at server-side).
>>
>> Currently one way to overcome this problem is manually modify the
>> auto-generated webservice proxy's source code. You can change the return
>> type from the "localhost.RunningReport[]" to
>> "Reports.Modules.RunningJobs.RunningReport[]". The drawback of this is
>> when you update the webservice refefence, your change will be
>> overwritten.
>> To avoid this, you can add a partial class file for the webservice
>> clienet
>> proxy class, and add a new method (the same signature and attributes as
>> the
>> original webmethod), and chang the return type to the one you want.

>
> As Steven has said, this will not work, as it will be overwritten every
> time you update your web reference.
>
> The correct solution is simply to use:
>
> localhost.RunningReports[] reportsArray = localrs.RunningReports();
> --
> John Saunders | MVP - Connected System Developer
>
>


Thank You for your help, that worked!

I also switched to WCF, which works very nice.


 
Reply With Quote
 
Steven Cheng
Guest
Posts: n/a
 
      10-13-2008
Hi Peter,

I'm glad that you've got it working. If there is anything else need help
later, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).


--------------------
>From: "Peter" <(E-Mail Removed)>
>References: <(E-Mail Removed)>

<OcpE$(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
>Subject: Re: Read WebService List<> data
>Date: Fri, 10 Oct 2008 16:17:19 -0500


>
>"John Saunders" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> ""Steven Cheng"" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi Peter,
>>>
>>> The problem you encountered, is caused by XML webservice does not expose
>>> implement details to client(only expose WSDL service description) for
>>> interop purpose. Therefore, for any custom types used in webservice, by
>>> default the client-side will generate a light weight delegate class to
>>> represent it. That's why, for your scenario, it reports the following
>>> error:
>>>
>>> ================
>>> Cannot implicitly convert type 'localhost.RunningReport[]' to
>>> 'Reports.Modules.RunningJobs.RunningReport[]'
>>> ===============
>>>
>>> here the "localhost.RunningReport" type is generated by the webservice
>>> client proxy(add webreference), while
>>> "Reports.Modules.RunningJobs.RunningReport" is your own type(the type
>>> used
>>> at server-side).
>>>
>>> Currently one way to overcome this problem is manually modify the
>>> auto-generated webservice proxy's source code. You can change the return
>>> type from the "localhost.RunningReport[]" to
>>> "Reports.Modules.RunningJobs.RunningReport[]". The drawback of this is
>>> when you update the webservice refefence, your change will be
>>> overwritten.
>>> To avoid this, you can add a partial class file for the webservice
>>> clienet
>>> proxy class, and add a new method (the same signature and attributes as
>>> the
>>> original webmethod), and chang the return type to the one you want.

>>
>> As Steven has said, this will not work, as it will be overwritten every
>> time you update your web reference.
>>
>> The correct solution is simply to use:
>>
>> localhost.RunningReports[] reportsArray = localrs.RunningReports();
>> --
>> John Saunders | MVP - Connected System Developer
>>
>>

>
>Thank You for your help, that worked!
>
>I also switched to WCF, which works very nice.
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to call a WEBSERVICE in another WEBSERVICE (AXIS/ TOMCAT) Cyril Java 2 06-01-2006 06:07 PM
Problem! webservice.htc calling nonsecure webservice from a secured ssl https webpage batista ASP .Net 1 01-26-2006 12:05 PM
Problem! webservice.htc calling nonsecure webservice from a secured ssl https webpage batista ASP .Net 0 01-26-2006 08:13 AM
WebService on Java server versus WebService on .NET Mr. x Java 2 10-09-2003 11:21 PM
use another webservice in a webservice Mr. x ASP .Net Web Services 0 09-26-2003 10:59 PM



Advertisments