【问题标题】:how to call magento soap webservice in windows form application?如何在 Windows 窗体应用程序中调用 magento soap webservice?
【发布时间】:2017-09-18 04:44:40
【问题描述】:

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

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

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

    private void button1_Click(object sender, EventArgs e)
    {

    }

app.config 如下:

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

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

我在谷歌搜索了很多主题,但似乎与我的情况略有不同......

有人知道怎么做吗?

我想做的就是

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

}

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

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

【问题讨论】:

    标签: winforms soap magento-1.9


    【解决方案1】:

    如果您已经添加了您的肥皂服务,您需要在代码中声明它,例如:

    `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 文件也是如此。您只需要知道该肥皂服务中实现了哪些功能/方法。

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

    【讨论】:

    • s26.postimg.org/5hz6xjg09/soap.png 无法使用 ServiceReference1 创建对象
    • 服务变量只是为了使其可读性的说明。变量不应有空格。
    • 您有实时 wsdl 文件供我测试吗?
    • ServiceReference1.Service service = new ServiceReference1.Service(); , .Service 用红色下划线标记
    • 我可以看看您是如何添加服务的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2016-11-20
    相关资源
    最近更新 更多