Unable to Convert String to System.Data.Services [Resolved]

Posted by Self-Innovator under C# on 4/15/2016 | Points: 10 | Views : 289 | Status : [Member] | Replies : 3
Hi i am getting type cast exception kindly help...


 public GeneralReport GetGeneralInfo(int StoreId)
{
var storeInfoWebService = new UATStoreReportServiceReference.oraclemdb1SoapClient("oraclemdb1Soap");
var logisticsInfoFromService = storeInfoWebService.GetLogistics(StoreId.ToString());
var result = (GeneralReport)logisticsInfoFromService;
}


the underlined place i'm getting exception

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Rajnilari2015 on: 4/18/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
@Self-Innovator, We have answered the same here http://www.dotnetfunda.com/forums/show/21320/getting-null-in-xml-attribute and it has been marked as answer.

--
Thanks & Regards,
RNA Team

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 4/16/2016 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
It is clear that logisticsInfoFromService object is not convertible to GeneralReport object. Ensure that either logisticsInfoFromService object is either inheriting GeneralReport or GeneralReport itself.

Look what GetLogistics method is returning and accordingly cast it.

Or manually retrieve the property of logisticsInfoFromService and set to GeneralReport object properties.

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 4/17/2016 [Member] Bronze | Points: 25

Up
0
Down
HI Sheo Sir,

Thanks for your response.
In continuation to my post i'm able to deserialize the code but still i'm getting the XML Attribute values as NULL, i tried some workaround to resolve it at my level kindly see the below code

Hi i'm getting the xml values as null kinldy help.

<pre lang="C#">public logistics GetGeneralInfo(int StoreId)
{
var storeInfoWebService = new UATStoreReportServiceReference.oraclemdb1SoapClient(&quot;oraclemdb1Soap&quot;);
var logisticsInfoFromService = storeInfoWebService.GetLogistics(StoreId.ToString());
XmlSerializer serializer = new XmlSerializer(typeof(logistics));
StringReader rdr = new StringReader(logisticsInfoFromService);
logistics resultingMessage = (logistics)serializer.Deserialize(rdr);
return resultingMessage;

}</pre>

This is my XML string coming in variable logisticsInfoFromService as
<b>
<results>
<response mode="all" value=""/>
<logistics>
<freight
rdc1="01 - HARVARD"
rdc2="01 - HARVARD"
freightrate="0 %"
offshoredelivery="Y"
stratcode="Y"
multipledelivery="N"
palletized="N"
totesshipped="0"
totesreturned="0"
toteslastdate="5/30/2001 12:00:00 AM"
containersshipped="0"
containersreturned="0"
containerslastdate="5/30/2001 12:00:00 AM"/>
<routes/>
</logistics>
</results></b>

I'm gettting the values for freightrate and OffshreDelivery as NULL

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response