如何从 VB.NET 调用 Magento API [英] How to call the Magento API from VB.NET
问题描述
Magento 有一个 API,似乎有些人通过 VB.NET 使用它,但我尝试了好几个小时后无法让它工作.
Magento has an API and it seems some people are using it via VB.NET but I cannot get it to work after trying for many hours.
我使用的是 Magento 1.7.0.2试图让 VB.NET 应用程序与 API 一起工作.我正在使用符合 WS-I 的 Web 服务设置.
I’m on Magento 1.7.0.2 Trying to get a VB.NET app working with the API. I’m using the WS-I compliant web service setting.
错误 1 自定义工具错误:无法导入 WebService/Schema.无法从命名空间urn:Magento"导入绑定Mage_Api_Model_Server_Wsi_HandlerBinding".来自命名空间urn:Magento"的端口类型Mage_Api_Model_Server_Wsi_HandlerPortType"上的操作catalogProductAttributeRemove"有以下语法错误:操作没有匹配的绑定.检查 Binding 部分中的操作、输入和输出名称是否与 PortType 部分中的相应名称匹配.d:\Documents\Visual Studio 2010\Projects\Mage\Mage\My Project\Settings.settings 1 1 Mage
Error 1 Custom tool error: Unable to import WebService/Schema. Unable to import binding ‘Mage_Api_Model_Server_Wsi_HandlerBinding’ from namespace ‘urn:Magento’. The operation ‘catalogProductAttributeRemove’ on portType ‘Mage_Api_Model_Server_Wsi_HandlerPortType’ from namespace ‘urn:Magento’ had the following syntax error: The operation has no matching binding. Check if the operation, input and output names in the Binding section match with the corresponding names in the PortType section. d:\Documents\Visual Studio 2010\Projects\Mage\Mage\My Project\Settings.settings 1 1 Mage
如果我尝试将其添加为服务引用(而不是 Web 引用),则会出现一组不同的错误.
if I try to add it as a Service Reference (instead of a Web Reference) I get a different set of errors.
无法导入 wsdl:binding无法导入 wsdl:port无法导入 wsdl:portType
Cannot import wsdl:binding Cannot import wsdl:port Cannot import wsdl:portType
错误 5 自定义工具错误:无法为服务引用ServiceReference1"生成代码.有关详细信息,请检查其他错误和警告消息.d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 Mage
Error 5 Custom tool error: Failed to generate code for the service reference ‘ServiceReference1’. Please check other error and warning messages for details. d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 Mage
警告 3 自定义工具警告:无法导入 wsdl:binding详细信息:导入 wsdl:binding 所依赖的 wsdl:portType 时出错.到 wsdl:portType 的 XPath://wsdl:definitions[@targetNamespace='urn:Magento']/wsdl:portType[@name='Mage_Api_Model_Server_Wsi_HandlerPortType']错误源的 XPath://wsdl:definitions[@targetNamespace='urn:Magento']/wsdl:binding[@name='Mage_Api_Model_Server_Wsi_HandlerBinding'] d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 法师
Warning 3 Custom tool warning: Cannot import wsdl:binding Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on. XPath to wsdl:portType: //wsdl:definitions[@targetNamespace=’urn:Magento’]/wsdl:portType[@name=’Mage_Api_Model_Server_Wsi_HandlerPortType’] XPath to Error Source: //wsdl:definitions[@targetNamespace=’urn:Magento’]/wsdl:binding[@name=’Mage_Api_Model_Server_Wsi_HandlerBinding’] d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 Mage
警告 4 自定义工具警告:无法导入 wsdl:port详细信息:导入 wsdl:port 所依赖的 wsdl:binding 时出错.xPath to wsdl:binding://wsdl:definitions[@targetNamespace='urn:Magento']/wsdl:binding[@name='Mage_Api_Model_Server_Wsi_HandlerBinding']错误源的 XPath://wsdl:definitions[@targetNamespace='urn:Magento']/wsdl:service[@name='MagentoService']/wsdl:port[@name='Mage_Api_Model_Server_Wsi_HandlerPort'] d:\Documents\VisualStudio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 Mage
Warning 4 Custom tool warning: Cannot import wsdl:port Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on. XPath to wsdl:binding: //wsdl:definitions[@targetNamespace=’urn:Magento’]/wsdl:binding[@name=’Mage_Api_Model_Server_Wsi_HandlerBinding’] XPath to Error Source: //wsdl:definitions[@targetNamespace=’urn:Magento’]/wsdl:service[@name=’MagentoService’]/wsdl:port[@name=’Mage_Api_Model_Server_Wsi_HandlerPort’] d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 Mage
警告 2 自定义工具警告:无法导入 wsdl:portType详细信息:运行 WSDL 导入扩展时引发异常:System.ServiceModel.Description.XmlSerializerMessageContractImporter错误:来自命名空间 urn:Magento 的名为 catalogProductAttributeRemoveRequest 的元素消息丢失.错误源的 XPath://wsdl:definitions[@targetNamespace='urn:Magento']/wsdl:portType[@name='Mage_Api_Model_Server_Wsi_HandlerPortType'] d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 法师
Warning 2 Custom tool warning: Cannot import wsdl:portType Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter Error: Element message named catalogProductAttributeRemoveRequest from namespace urn:Magento is missing. XPath to Error Source: //wsdl:definitions[@targetNamespace=’urn:Magento’]/wsdl:portType[@name=’Mage_Api_Model_Server_Wsi_HandlerPortType’] d:\Documents\Visual Studio 2010\Projects\Mage\Mage\Service References\ServiceReference1\Reference.svcmap 1 1 Mage
有人可以给我非常明确的指令/代码来说明如何拨打电话并获得结果吗?我什至似乎无法获得正确的初始配置.我已经下载了其他人在线提供的一些代码,但如果不起作用——可能是因为它适用于较早的版本.
Can someone give me very explicit instruction/code on how to make a call and get a result? I can't even seem to get the initial configuration correct. I've downloaded some code others have provided online, but if doesn't work--probably because it was for a earlier version.
推荐答案
Function getHTTPStream() As String
Dim myh As HttpWebRequest = _
HttpWebRequest.Create("http://yourmagentoweb/soap/api/?wsdl")
myh.Timeout = 30000
myh.UserAgent = "Test"
Dim myR As HttpWebResponse = myh.GetResponse()
Dim myEnc As Encoding = Encoding.GetEncoding(1252)
Dim mySr As StreamReader = New StreamReader(myR.GetResponseStream(), myEnc)
Return mySr.ReadToEnd()
End Function
该代码显然需要调整 - 我没有时间美化这些东西
That code needs tweaking obviously- i have not got time to prettify this stuff
来自阿比德侯赛因的链接
from Abid Hussain's link
1.使用 wdsl 工具,我通过调用创建了一个 .vb 源文件:
wsdl/language:VB/out:MageProxyClass.vb http:///api/v2_soap?wsdl
wsdl /language:VB /out:MageProxyClass.vb http:///api/v2_soap?wsdl
2.之后我用VB命令行编辑器将源文件编译成dll.
vbc/out:MageProxyClass.dll/t:library/r:System.XML.dll,System.Web.Services.dll MageProxyClass.vb
vbc /out:MageProxyClass.dll /t:library /r:System.XML.dll,System.Web.Services.dll MageProxyClass.vb
3.最后,我能够创建在我的 MageProxyClass.dll 中定义的 MagentoService 类的实例
Private WithEvents msvc As New MagentoService()
4.示例:
Public Class main
Private WithEvents msvc As New MagentoService()
Private ssid As String
Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
ListBox1.Items.Add("Trying to connect")
msvc.loginAsync("xxxx", "xxxxxxxxxxxxxxxx")
End Sub
Public Sub MageLoginComplete(ByVal sender As System.Object, ByVal e As loginCompletedEventArgs) Handles msvc.loginCompleted
ListBox1.Items.Add("Login completed")
ssid = e.Result
ListBox1.Items.Add(String.Concat("Session ID: ", ssid))
End Sub
End Class
这篇关于如何从 VB.NET 调用 Magento API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!