Thursday, 20 November 2014

Sending SOAP request using angularjs $HTTP post

In my first project with multi-device hybrid app using cordova+angularjs I did not know how to attach or where to setup the soap request (I'm dealing with an old ASMX webservice) inside the angularjs $http.post syntax. After hours of searching I found out that you can actually include the soap request message inside the "data" parameter of the $http.post command - post(url, data, [config]). See example codes below.


var soapMessage = '<?xml version="1.0" encoding="utf-8"?>\
                            <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">\
                              <soap12:Header>\
                                <SvcAuthHdr_GetDistrAgreementRecords xmlns="http://tempuri.org/">\
                                  <token>XXXXXX23232SSSS</token>\
                                  <username>9999</username>\
                                  <distance>100</distance>\
                                  <numdaysold>150</numdaysold>\
                                </SvcAuthHdr_GetDistrAgreementRecords>\
                              </soap12:Header>\
                              <soap12:Body>\
                                <GetDistrAgreementRecords xmlns="http://tempuri.org/" />\
                              </soap12:Body>\
                            </soap12:Envelope>';

        var headers = {
            'Content-Type': 'text/xml; charset=utf-8'
        };
        $scope.leadslist = [];

        $http.post(url, soapMessage,
                 { "headers": headers })
                 .success(function (data) {
                     var srchString = '<GetDistrAgreementRecordsResult>0[';
                     var startIdx = data.indexOf(srchString);
                     var endIdx = data.indexOf(']</GetDistrAgreementRecordsResult>');

                     var jsonString = '{"leads":[' + data.substring(startIdx + srchString.length, endIdx) + "]}";

                     var jsonObject = JSON.parse(jsonString);

                     $scope.leadslist = jsonObject.leads;

                 });

Thursday, 6 November 2014

Visual Studio Multi-device Hybrid app build error - failed to fetch package information org.apache.cordova.*

One of the problem I had encountered running a new Multi-device Hybrid project in Visual Studio is during the build and with pre-selected plugins enabled I am getting this build errors -


------ Adding plugin: org.apache.cordova.battery-status
  Calling plugman.fetch on plugin "org.apache.cordova.battery-status"
  
  C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda\node_modules\q\q.js:126
                      throw e;
                            ^
EXEC : error : Failed to fetch package information for org.apache.cordova.battery-status
      at C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\node_modules\cordova-lib\src\plugman\registry\registry.js:32:20
      at Request.cb [as _callback] (C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\node_modules\cordova-lib\src\plugman\registry\registry.js:251:9)
      at self.callback (C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\node_modules\cordova-lib\node_modules\request\index.js:148:22)
      at Request.emit (events.js:117:20)
      at ClientRequest.self.clientErrorHandler (C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda\node_modules\cordova\node_modules\cordova-lib\node_modules\request\index.js:257:10)
      at ClientRequest.emit (events.js:95:17)
      at Socket.socketErrorListener (http.js:1551:9)
      at Socket.emit (events.js:95:17)
      at net.js:440:14
      at process._tickCallback (node.js:419:13)
C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda-targets\Microsoft.MDA.targets(99,5): error MSB3073: The command ""C:\Users\myuser\AppData\Roaming\npm\node_modules\vs-mda\vs-cli" build --platform "Android" --configuration "Debug" --projectDir . --projectName "CordovaApp" --language "en-US" --buildServerUrl "" --buildTarget "AndroidEmulator"" exited with code 8.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


After a few hours of searching and pulling of hairs, I found out that you can actually install the plugins manually and copying the downloaded plugins straight into your visual studio project. See my own post here in stackoverflow
:
http://stackoverflow.com/questions/26745635/visual-studio-multi-device-hybrid-failed-to-fetch-package-information-error/26749745#26749745

Monday, 3 November 2014

node.js NPM tunnelling problem

Had a problem connecting node.js/npm via my work pc which was inside a corporate firewall. Followed the following settings and it works for me. Key thing is make sure it connects via your corporate proxy.

Check your settings first.

npm config ls -l


Then set the following configs.

npm config set registry http://registry.npmjs.org/

npm config set strict-ssl = false

npm config set proxy "http://<userid>:<password>@<proxy url>:8080"


npm config set https-proxy "http://<userid>:<password>@<proxy url>:8080"


Your user may need to include the domain of your company, if so make sure it's encoded (e.g. "\", "%5C").