Magento News
C# Problem adding multiple web references to different versions of the same 3rd party API?
I have a problem in my C# ASP.NET MVC web app where we are trying to add multiple references to different versions of the Magento API.
Basically my app needs to be able to connect to different Magento ecommerce stores. Some of these stores could be version 1.4, some could be 1.5 and so on. To handle this situation I have added multiple web references, one for each of the versions:
<applicationSettings>
<WebApp.Properties.Settings>
<setting name="WebApp_MagentoWebReference_MagentoService"
serializeAs="String">
<value>http://example.com/magento1411/index.php/api/v2_soap/index/</value>
</setting>
<setting name="WebApp_Magento1510WebReference_MagentoService"
serializeAs="String">
<value>http://example.com/magento1510/index.php/api/v2_soap/index/</value>
</setting>
</WebApp.Properties.Settings>
</applicationSettings>
And then in the code I make sure to create an instance using the right web reference that matches the version I am targeting:
string url = "http://example.com/magento1411/index.php/api/v2_soap/";
_magentoService = new MagentoWebReference.MagentoService();
_magentoService.Url = url;
string apiUser = "user";
string apiKey = "key";
sessionId = _magentoService.login(apiUser, apiKey);
var magentoProductList = _magentoService.catalogProductList(sessionId, null, null);
You can see that I am deliberately creating the version 1.4 web reference when requesting the product list from a version 1.4 shop. However when this code runs it fails with this error:
Cannot assign object of type WebApp.Magento1510WebReference.salesOrderInvoiceEntity[]
to an object of type WebApp.MagentoWebReference.salesOrderInvoiceEntity[].
For some reason the return value is of type Magento1510WebReference.salesOrderInvoiceEntity.
Is there any known problem adding multiple web references like this? Is Visual Studio or IIS getting confused between the two references?
This is the full stack trace:
System.Exception: There was a problem recieving a list of invoices from mageto store: http://example.com ---> System.InvalidOperationException: There is an error in XML document (2, 485). ---> System.InvalidCastException: Cannot assign object of type WebApp.Magento1510WebReference.salesOrderInvoiceEntity[] to an object of type WebApp.MagentoWebReference.salesOrderInvoiceEntity[].
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read351_salesOrderInvoiceListResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer469.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at WebApp.MagentoWebReference.MagentoService.salesOrderInvoiceList(String sessionId, filters filters) in C:srcWebApp.2010WebApp.UIWeb ReferencesMagentoWebReferenceReference.cs:line 3073
at WebApp.Controllers.Magento.MagentoController.GetLatestInvoices() in C:srcWebApp.2010WebApp.UIControllersMagentoMagentoController.cs:line 217
--- End of inner exception stack trace ---
I can see that when the response comes back from the Magento API that the XmlSerializer.Deserialize is getting confused and thinks that the XML comes from the Magento 1.5 reference, not the Magento 1.4 reference. The question is why does it do this, and how can it be fixed?
C# Problem adding multiple web references to different versions of the same 3rd party API?
Possibly Related Posts:
- Database query different results
- Menu highlight in magento under admin
- magento disable a banner on certain category pages or have a banner with multiple links
- Magento, using ACL for frontend. Possible?
- Magento IE-7 Fix In Windows XP
RSS Feed