Magento (os コマース ソリューション) が提供する API WebService をインターフェイスしようとしています。
この magento の Web サービスでは、メソッドごとにセッション処理が必要なので ( と を除くlogin
) endSession
、生成された WCF プロキシ クラスを独自のクラス内にラップして、すべてのセッション処理を行います。
ただし、派生クラスが元の元の WCF ラッパーとは異なる動作をする理由を一生理解できません。特に長時間実行されるメソッドは失敗します (このスタック トレースでは:
System.ServiceModel.FaultException: Internal Error. Please see log for details.
Server stack trace:
bei System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
bei System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
bei System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
bei System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
これは私のラッパー クラスの (最初のドラフト) です (MagentoService は、Magento Webservice に対して生成されたプロキシ クラスです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace MagentoConnector
{
public class MagentoController : MagentoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient
{
private string username = "apiusername";
private string password = "apiuserpassword";
private string sessionId = null;
public MagentoController(string url) : base()
{
if(!string.IsNullOrEmpty(url)) {
if(!url.ToLower().StartsWith("http://")) url = "http://" + url;
if(!url.EndsWith("/")) url += "/";
url += "magento/index.php/api/v2_soap/index/";
this.Endpoint.Address = new EndpointAddress(new Uri(url), this.Endpoint.Address.Identity, this.Endpoint.Address.Headers);
}
this.Open();
}
public MagentoController(string url, string username, string password) : this(url)
{
if(!string.IsNullOrEmpty(username)) {
this.username = username;
}
if(!string.IsNullOrEmpty(password)) {
this.password = password;
}
sessionId = this.login(this.username, this.password);
}
public new string login(string username, string password)
{
if(!string.IsNullOrEmpty(sessionId)) {
this.endSession(sessionId);
}
sessionId = base.login(username, password);
this.username = username;
this.password = password;
return sessionId;
}
public string login()
{
return login(this.username, this.password);
}
public void logoff()
{
if(!string.IsNullOrEmpty(sessionId)) {
this.endSession(sessionId);
}
}
~MagentoController()
{
try {
logoff();
} catch(Exception) {
;
}
}
public MagentoService.catalogCategoryTree catalogCategoryTree(string parentId, string storeView)
{
return base.catalogCategoryTree(sessionId, parentId, storeView);
}
public static MagentoService.catalogCategoryTree getCatalogTree(string parentId, string storeView)
{
string sessionId = null;
MagentoService.catalogCategoryTree myTree = null;
MagentoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient myService = new MagentoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient();
try {
myService.Open();
sessionId = myService.login("applus-dev", "FL1LBveiNW8nGOg9QRa4z");
myTree = myService.catalogCategoryTree(sessionId, null, null);
} finally {
if(myService != null && !string.IsNullOrEmpty(sessionId)) {
myService.endSession(sessionId);
}
}
return myTree;
}
}
}
静的メソッドgetCatalogTree
に注意してください。これは と直接インターフェースしMagentoService
、正常に動作します (magento のすべてのカテゴリ ノードのツリーを返します)。基本メソッドの呼び出し時にメソッドcatalogCategoryTree
が失敗し、上記のエラーが発生します。
呼び出しコードは次のとおりです。
MagentoController myService = new MagentoController(null, null, null);
MagentoService.catalogCategoryTree myTree = myService.catalogCategoryTree(parentId, storeView);
なぜこれが起こっているのかわかりません。静的メソッドと基本クラスを呼び出すメソッドの違いは何ですか?
それとは別に、magento Web サービスを使用することは、.NET を使用した a#* (v2 ソープ サービスで改善されている) の苦痛です...
敬具、
アルント