Archive

Archive for March, 2010

The Apache2.2 service terminated with service-specific error 1 (0x1).

Categories: Uncategorized

Importing a CSV file into Amazon SimpleDB

Here’s some code to import a CSV file into a Amazon SimpleDB database

            Console.WriteLine("Connecting to Amazon Simple DB");
    
            NameValueCollection appConfig = ConfigurationManager.AppSettings;

            AmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient(
                appConfig["AWSAccessKey"],
                appConfig["AWSSecretKey"]
                );

            // Setup Flights DataStore
            String domainName = "CSV";
            CreateDomainRequest createDomain = (new CreateDomainRequest()).WithDomainName(domainName);
            sdb.CreateDomain(createDomain);

            Console.WriteLine("Created flights DB on Amazon");

            string strCSVFile = @"C:MyFile.csv";
            FileStream fsCSV = new FileStream(strCSVFile, FileMode.Open, FileAccess.Read);
            StreamReader srCSV = new StreamReader(fsCSV);
            string strHeaderLine = srCSV.ReadLine();
            string[] strHeaders = Regex.Split(strHeaderLine, ",");
            // Remove Inverted Commas
            for (int i = 0; i < strHeaders.Length; i++)
            {
                strHeaders[i] = strHeaders[i].Replace(""", "");
            }

            Console.WriteLine("Read column headers");

            string strDataLine = srCSV.ReadLine();
            while(!string.IsNullOrEmpty(strDataLine))
            {
                string[] strData = Regex.Split(strDataLine, ",");
                if (strData.Length < strHeaders.Length) continue;
                strDataLine = srCSV.ReadLine();
                PutAttributesRequest putAttributesAction = new PutAttributesRequest().WithDomainName(domainName).WithItemName(Guid.NewGuid().ToString());
                List<ReplaceableAttribute> attributes = putAttributesAction.Attribute;               
                for (int i = 0; i < strHeaders.Length-1; i++)
                {
                    strData[i] = strData[i].Replace(""", "");
                    attributes.Add(new ReplaceableAttribute().WithName(strHeaders[i]).WithValue(strData[i]));              
                }
                sdb.PutAttributes(putAttributesAction);
                Console.WriteLine(strDataLine);
            }

Categories: Uncategorized

More than one endpoint configuration for that contract was found

In VS 2008, when you add a web refrence to a windows forms app, it works a little differently, createing a "service" reference. This causes
some problems with web services that have more than one binding, i.e. designed to support Soap 1.0 and Soap 1.2.

This was the first sign of this nasty quirk;
An endpoint configuration section for contract ‘FreebieSMSWebservice.BulkSMSSoap’ could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.

If you open the Configuration.svcinfo file, then scroll to the end right, you’ll see the xml (below). Where I’ve highlighted the endpoint names;
So then the client code becomes:

            BulkSMSSoapClient SMS = new BulkSMSSoapClient("BulkSMSSoap");
            double dCredit = SMS.GetRemainingCredit("xxxx", "xxxx");
            MessageBox.Show(dCredit.ToString());

Where the parameter sent to the constructor is the endpoint name.

<?xml version="1.0" encoding="utf-8"?>
<configurationSnapshot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns="urn:schemas-microsoft-com:xml-wcfconfigurationsnapshot">
  <behaviors />
  <bindings>
    <binding digest="System.ServiceModel.Configuration.BasicHttpBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data hostNameComparisonMode=&quot;StrongWildcard&quot; maxBufferSize=&quot;65536&quot; messageEncoding=&quot;Text&quot; name=&quot;BulkSMSSoap&quot; textEncoding=&quot;utf-8&quot; transferMode=&quot;Buffered&quot;&gt;&lt;readerQuotas maxArrayLength=&quot;16384&quot; maxBytesPerRead=&quot;4096&quot; maxDepth=&quot;32&quot; maxNameTableCharCount=&quot;16384&quot; maxStringContentLength=&quot;8192&quot; /&gt;&lt;security mode=&quot;None&quot;&gt;&lt;message algorithmSuite=&quot;Default&quot; clientCredentialType=&quot;UserName&quot; /&gt;&lt;transport clientCredentialType=&quot;None&quot; proxyCredentialType=&quot;None&quot; realm=&quot;&quot; /&gt;&lt;/security&gt;&lt;/Data&gt;" bindingType="basicHttpBinding" name="BulkSMSSoap" />
    <binding digest="System.ServiceModel.Configuration.CustomBindingElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089:&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data name=&quot;BulkSMSSoap12&quot;&gt;&lt;httpTransport allowCookies=&quot;false&quot; authenticationScheme=&quot;Anonymous&quot; bypassProxyOnLocal=&quot;false&quot; hostNameComparisonMode=&quot;StrongWildcard&quot; keepAliveEnabled=&quot;true&quot; manualAddressing=&quot;false&quot; maxBufferPoolSize=&quot;524288&quot; maxBufferSize=&quot;65536&quot; maxReceivedMessageSize=&quot;65536&quot; proxyAuthenticationScheme=&quot;Anonymous&quot; realm=&quot;&quot; transferMode=&quot;Buffered&quot; unsafeConnectionNtlmAuthentication=&quot;false&quot; useDefaultWebProxy=&quot;true&quot; /&gt;&lt;textMessageEncoding maxReadPoolSize=&quot;64&quot; maxWritePoolSize=&quot;16&quot; messageVersion=&quot;Soap12&quot; writeEncoding=&quot;utf-8&quot;&gt;&lt;readerQuotas maxArrayLength=&quot;16384&quot; maxBytesPerRead=&quot;4096&quot; maxDepth=&quot;32&quot; maxNameTableCharCount=&quot;16384&quot; maxStringContentLength=&quot;8192&quot; /&gt;&lt;/textMessageEncoding&gt;&lt;/Data&gt;" bindingType="customBinding" name="BulkSMSSoap12" />
  </bindings>
  <endpoints>
    <endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://www.freebiesms.co.uk/bulksms.asmx&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;BulkSMSSoap&quot; contract=&quot;FreebieSMSWebservice.BulkSMSSoap&quot; name=&quot;BulkSMSSoap&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://www.freebiesms.co.uk/bulksms.asmx&quot; binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;BulkSMSSoap&quot; contract=&quot;FreebieSMSWebservice.BulkSMSSoap&quot; name=&quot;BulkSMSSoap&quot; /&gt;" contractName="FreebieSMSWebservice.BulkSMSSoap" name="BulkSMSSoap" />
    <endpoint normalizedDigest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://www.freebiesms.co.uk/bulksms.asmx&quot; binding=&quot;customBinding&quot; bindingConfiguration=&quot;BulkSMSSoap12&quot; contract=&quot;FreebieSMSWebservice.BulkSMSSoap&quot; name=&quot;BulkSMSSoap12&quot; /&gt;" digest="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;&lt;Data address=&quot;http://www.freebiesms.co.uk/bulksms.asmx&quot; binding=&quot;customBinding&quot; bindingConfiguration=&quot;BulkSMSSoap12&quot; contract=&quot;FreebieSMSWebservice.BulkSMSSoap&quot; name=&quot;BulkSMSSoap12&quot; /&gt;" contractName="FreebieSMSWebservice.BulkSMSSoap" name="BulkSMSSoap12" />
  </endpoints>
</configurationSnapshot>

Categories: Uncategorized