I'm creating a C# program that can create customer into the Magento server. For some reason, I required to do it with SOAP V1. The documentation only provide example in PHP.
From the API documentation. These lines of codes are for creating a customer data.
//Creating PortTypeClient object.
$client = new SoapClient('http://magentohost/api/soap/?wsdl');
//Login to get API permission
$session = $client->login('apiUser', 'apiKey');
//Create customer
$result = $client->call($session,'customer.create',array(array('email' => 'mail@example.org', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1)));
My problem is I'm having trouble with convert that array in $result = $client->call
into C# code. From what I understand, I create a Dictionary object mimicking the PHP array like this
//Creating PortTypeClient object.
Mage_Api_Model_Server_HandlerPortTypeClient mservice = new Mage_Api_Model_Server_HandlerPortTypeClient();
//Login to get API permission
var mlogin = mservice.login(MiscFunc.getSettingSoapUser(), MiscFunc.getSettingSoapApikey());
//Create a dictionary object (mimicking PHP array)
IDictionary<Object, Object> customerData = new Dictionary<Object, Object>()
{
{ "email" , (string) customerEmail },
{ "firstname", (string) customerFName },
{ "lastname", (string) customerLName() },
{ "password", (string) customerTel() },
{ "website_id", (int) 1 },
{ "store_id", (int) 1 },
{ "group_id", (int) 1 },
{ "prefix", (string) customerPrefix() },
{ "dob", (string) customerBdate() },
{ "gender", (int) customerGender } //1-Male;2-Female
};
// Create customer
mservice.call(mlogin, "customer.create", customerData);
I tried above codes and looks like it wrong. My Visual Studio threw me this error
System.ServiceModel.CommunicationException
HResult=0x80131501
Message=There was an error in serializing body of message : 'There was an error generating the XML document.'. Please see InnerException for more details.
Source=mscorlib
Inner Exception 1:
InvalidOperationException: There was an error generating the XML document.
Inner Exception 2:
NotSupportedException: The type System.Collections.Generic.Dictionary`2[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] is not supported because it implements IDictionary.
User contributions licensed under CC BY-SA 3.0