Git Product home page Git Product logo

angular-soap's Introduction

angular-soap

An Angular port of a JavaScript SOAP Client into a factory that has a similar syntax to $http.

Usage

Before using the factory, you must import the two scripts and its module:

<script src="soapclient.js"></script>
<script src="angular.soap.js"></script>
angular.module('myApp', ['angularSoap']);

Then, wherever you are going to consume it, make a reference to the $soap service for dependency injection:

.factory("testService", ['$soap',function($soap){
//use it here
}])

$soap has one method, post, which accepts the following paramaters:

Parameter Description Example
url The base URL of the service "http://www.cooldomain.com/SoapTest/webservicedemo.asmx"
action The action you want to call "HelloWorld"
params An object of parameters to pass to the service { name: "Andrew" }

Syntax:

$soap.post(url,action,params);

Similar to $http methods, $soap.post returns a promise that you can act upon.

$soap.post(url,action,params).then(function(response){
	//Do Stuff
});

NOTE: Response will be a javascript object containing the response mapped to objects. Do a console.log of response so you can see what you are working with.

Example 1: Hello World

A basic "Hello World" with no parameters.

angular.module('myApp', ['angularSoap'])

.factory("testService", ['$soap',function($soap){
	var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx";

	return {
		HelloWorld: function(){
			return $soap.post(base_url,"HelloWorld");
		}
	}
}])

.controller('MainCtrl', function($scope, testService) {

  testService.HelloWorld().then(function(response){
	$scope.response = response;
  });
  
})

Example 2: Invoke with Parameters

A basic method call with parameters.

angular.module('myApp', ['angularSoap'])

.factory("testService", ['$soap',function($soap){
	var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx";

	return {
		CreateUser: function(firstName, lastName){
			return $soap.post(base_url,"CreateUser", {firstName: firstName, lastName: lastName});
		}
	}
}])

.controller('MainCtrl', function($scope, testService) {

  testService.CreateUser($scope.firstName, $scope.lastName).then(function(response){
	$scope.response = response;
  });
  
})

Example 3: Get Single Object

A basic method call to get a single object.

angular.module('myApp', ['angularSoap'])

.factory("testService", ['$soap',function($soap){
	var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx";

	return {
		GetUser: function(id){
			return $soap.post(base_url,"GetUser", {id: id});
		}
	}
}])

.controller('MainCtrl', function($scope, testService) {

  testService.GetUser($scope.id).then(function(user){
	console.log(user.firstName);
	console.log(user.lastName);
  });
  
})

Example 4: Get Many Objects

A basic method call to get a collection of objects.

angular.module('myApp', ['angularSoap'])

.factory("testService", ['$soap',function($soap){
	var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx";

	return {
		GetUsers: function(){
			return $soap.post(base_url,"GetUsers");
		}
	}
}])

.controller('MainCtrl', function($scope, testService) {

  testService.GetUsers().then(function(users){
	for(i=0;i<users.length;i++){
		console.log(users[i].firstName);
		console.log(users[i].lastName);
	}
  });
  
})

Example 5: Set Connection Credentials

Set the credentials for the connection before sending any requests.

angular.module('myApp', ['angularSoap'])

.factory("testService", ['$soap',function($soap){
	var base_url = "http://www.cooldomain.com/SoapTest/webservicedemo.asmx";
	
	$soap.setCredentials("username","password");

	return {
		GetUsers: function(){
			return $soap.post(base_url,"GetUsers");
		}
	}
}])

.controller('MainCtrl', function($scope, testService) {

  testService.GetUsers().then(function(users){
	for(i=0;i<users.length;i++){
		console.log(users[i].firstName);
		console.log(users[i].lastName);
	}
  });
  
})

angular-soap's People

Contributors

andrewmcgivery avatar jlast avatar aleksmeshkov avatar gpelaez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.