0

Magento API の異なるバージョンへの複数の参照を追加しようとしている C# ASP.NET MVC Web アプリに問題があります。

基本的に、私のアプリはさまざまな Magento e コマース ストアに接続できる必要があります。これらのストアの一部はバージョン 1.4 である可能性があり、一部は 1.5 である可能性があります。この状況に対処するために、各バージョンに 1 つずつ、複数の Web 参照を追加しました。

  <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>

次に、コードで、ターゲットとするバージョンに一致する適切な Web 参照を使用してインスタンスを作成するようにします。

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);

バージョン 1.4 のショップに製品リストをリクエストする際に、意図的にバージョン 1.4 の Web リファレンスを作成していることがわかります。ただし、このコードを実行すると、次のエラーで失敗します。

Cannot assign object of type WebApp.Magento1510WebReference.salesOrderInvoiceEntity[] 
to an object of type WebApp.MagentoWebReference.salesOrderInvoiceEntity[].

何らかの理由で、戻り値の型はMagento1510WebReference.salesOrderInvoiceEntityです。

このような複数の Web 参照を追加する既知の問題はありますか? Visual Studio または IIS が 2 つの参照の間で混乱していますか?

これは完全なスタック トレースです。

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:\src\WebApp.2010\WebApp.UI\Web References\MagentoWebReference\Reference.cs:line 3073
   at WebApp.Controllers.Magento.MagentoController.GetLatestInvoices() in C:\src\WebApp.2010\WebApp.UI\Controllers\Magento\MagentoController.cs:line 217
   --- End of inner exception stack trace ---

XmlSerializer.Deserialize が混乱し、XML が Magento 1.4 リファレンスではなく Magento 1.5 リファレンスから来ていると考える応答が Magento API から返されたことがわかります。問題は、なぜこれを行うのか、どうすれば修正できるのかということです。

編集:

私が疑ったように、Magento API からの応答の SOAP エンベロープは、実際には両方のバージョンで同じです。

1.4.1 soap = <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:loginResponse><loginReturn xsi:type="xsd:string">6325f7753ea72ba70e0a04254d58abe5</loginReturn></ns1:loginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
1.5.1 soap = <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:loginResponse><loginReturn xsi:type="xsd:string">90ebce956623bb7e1637165306de40d0</loginReturn></ns1:loginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

つまり、応答を受信したときに、Xml デシリアライザーはどちらの Web 参照を使用するかを判断できません。これは、両方の Web 参照が応答の署名と一致するためです。そして、Magento1411 参照である必要があるときに、Magento1510 参照を使用して逆シリアル化することになります。これについて私にできることはありますか?(参照を別々のプロジェクトに分割することを提案する答えを試し始めました)

4

1 に答える 1

1

WCF サービスが適切にバージョン管理されている場合、1.5 アセンブリを使用していても、1.4 バージョンと通信できるはずです。これを試しましたか?

それがうまくいかない場合は、各バージョンのプロキシを新しいプロジェクトに分ける必要があると思います。このようにして、プロキシが現在のバージョンのみを認識していることを確認し、名前空間の競合を回避できます。

于 2011-07-11T06:06:43.003 に答える