如何在Windows窗体应用程序中调用magento soap webservice?
问题描述:
我有这样http://example.com/index.php/api/v2_soap/?wsdl(它是一个Magento的网站),用户名密码为abc肥皂链接,123如何在Windows窗体应用程序中调用magento soap webservice?
我只是说,在解决方案资源管理服务引用的名称是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)创建肥皂客户端对象后,我如何调用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;
}
---------------------------- answer-- ---------------------------
与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());
答
如果你有已经添加了您的肥皂服务,您需要的是在您的代码中声明如下:
`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服务中实现了哪个函数/方法。
.........................
https://s26.postimg.org/5hz6xjg09/soap.png can not使用ServiceReference1 – hkguile
创建对象https://s26.postimg.org/80kvy81qh/soap2.png查看ServiceReference1 – hkguile
里面的内容仅仅是为了使其易读。变量应该没有空格。 –