如何在Windows窗体应用程序中调用magento soap webservice?

时间:2017-09-18 04:44:40

标签: winforms soap magento-1.9

我有这样的肥皂链接http://example.com/index.php/api/v2_soap/?wsdl(它是一个magento网站),用户名密码是abc,123

我刚刚在解决方案资源管理器中添加了一个服务引用,名称为ServiceReference1

我创建了一个按钮(使用vs2015,项目名称是printOrder),代码如下:

    <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
            <startup> 
                <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
            </startup>
            <system.serviceModel>
                <bindings>
                    <basicHttpBinding>
                        <binding name="Binding" />
                    </basicHttpBinding>
                </bindings>
                <client>
                    <endpoint address="http://example.com/index.php/api/v2_soap/index/"
                        binding="basicHttpBinding" bindingConfiguration="Binding"
                        contract="ServiceReference1.PortType" name="Port" />
                </client>
            </system.serviceModel>
    </configuration>

app.config如下:

$cs = getSesstion();
$result = $cs['client']->salesOrderShipmentInfo($cs['session'], '200001811');

$complexFilter = array(
    'complex_filter' => array(
        array(
            'key' => 'orderIncrementId',
            'value' => array('key' => 'in', 'value' => '100004496')
        )
    )
);
var_dump($cs);
//$result = $cs['client']->salesOrderInfo($cs['session'],'100004496');
//var_dump($result);

function getSesstion() {

    $client = new SoapClient('http://example.com/index.php/api/v2_soap/?wsdl');

    $username = 'vtec';
    $apikey= 'Abcd1234';


    $session = $client->login($username, $apikey);
    $cs = array();
    $cs['client'] = $client;
    $cs['session'] = $session;
    return $cs;

}

所以,
1)如何使用用户名和密码创建soap客户端对象?
2)创建soap客户端对象后,如何调用Web服务?

我在谷歌搜索了很多主题,但似乎与我的案例有很小不同......

任何人都知道如何做到这一点?

我想做的同样是

        ServiceReference1.PortTypeClient client = new ServiceReference1.PortTypeClient();
        string session = client.login("vtec","Abcd1234");

        Console.WriteLine(session);
        //client.(session, "product_stock.list", "qqaz");
        var result = client.salesOrderInfo(session, "145000037");

        //client.endSession(session);
        Console.WriteLine(result.increment_id.ToString());

----------------------------答案------------------ -----------
在Regie Baquero的帮助下,我发现的正确代码是

//*[@id="job_list"]/tbody/tr[' + tr.to_s + ']/td[2]/span[1]/a/span

1 个答案:

答案 0 :(得分:0)

如果您已经添加了soap服务,那么您需要在代码中声明它:

`ServiceReference1.Service service variable = new ServiceReference1.Service();`

以便您访问soap服务中的方法或功能。

示例代码如果您已在visual studio c#中编写了soap服务,则代码应如下所示:

[WebMethod]
public bool Password_Verification(string password)
{
      if(password=="12345")
    {
        return true;
     }
}

您可以使用

访问它
        `ServiceReference1.Service service variable = new ServiceReference1.Service();`
             bool verify = service variable.Password_Verification("12345");

与wsdl文件相同。你只需要知道在soap服务中实现了什么功能/方法。

.........................