2012-08-23 63 views
5

Magento有一个API,似乎有些人通过VB.NET使用它,但在尝试了很多小时后我无法使它工作。如何从VB.NET调用Magento API

我在Magento 1.7.0.2 试图获得一个VB.NET应用程序与API的工作。 我正在使用符合WS-I的Web服务设置。

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引用),我得到一组不同的错误。

无法导入WSDL:结合 无法导入WSDL:端口 无法导入WSDL:portType的

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

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

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

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

能有人给我如何拨打电话,并得到的结果非常明确的指令/代码?我似乎甚至无法得到正确的初始配置。我已经下载了其他人在线提供的一些代码,但是如果不起作用 - 可能是因为它是针对早期版本的。

+3

您能浏览浏览器中的网络服务吗? – Kiddo

+4

是的,我在这里有一个测试网站: http://testshop.tokyorealtime.com/api/v2_soap?wsdl=1 我认为API XML可能有问题,或者与.NET稍有不兼容,但似乎其他人已设法使其工作。 –

回答

4
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 

代码需要调整obviously-我没有时间从阿比德·侯赛因的链接

1.使用WDSL工具,我通过调用创建的.vb源文件美化这东西


wsdl /language:VB /out:MageProxyClass.vb http:///api/v2_soap?wsdl

2.然后我用VB COMAND行编辑器来编译的资源文件到DLL。

vbc /out:MageProxyClass.dll /t:library /r:System.XML.dll,System.Web.Services.dll MageProxyClass.vb

3.最后我能创造我MageProxyClass.dll定义

Private WithEvents msvc As New MagentoService() 

4.示例MagentoService类的一个实例:

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

我在发布之前已按照这些说明进行操作,但它们无效。无论如何,不​​需要将代码编译到DLL中,只需在VB.NET项目中访问它即可。你真的开始工作了吗? 我要创建一个新的赏金,因为虽然stackoverflow会自动授予你点数,但我的问题仍然没有解决方案。 –

+1

似乎现在工作,我升级到VB 2013 –

3

最后得到了这个工作。

添加您的web服务如常(它将无法编译,但增加也无妨)

打开Magento的。wsdl(或者你的VS在你的web引用中调用wsdl文件的任何东西),并完全移除对catalogProductAttributeRemove的调用。

<!--wsdl:operation name="catalogProductAttributeRemove"> 
    <wsdl:documentation>Delete attribute</wsdl:documentation> 
    <wsdl:input message="typens:catalogProductAttributeRemoveRequest" /> 
    <wsdl:output message="typens:catalogProductAttributeRemoveResponse" /> 
</wsdl:operation--> 

火了Visual Studio命令提示符并导航到你的项目,那么 “Web引用”

类型: WSDL /语言:VB /out:Reference.vb Magento.wsdl /命名空间: com.yourwebservicename.www

这将正确生成需要继续的reference.vb文件。