angularjs and soap webservice - angularjs

I am trying to call soap webservice through angular js code but i am getting below exception while sending xml through xmlHttp.send method where xmlHttp is
var xmlHttp = SOAPClient._getXmlHttp();
Failed to load resource: the server responded with a status of 401 (Unauthorized).
When i sent the same request through soap UI Client,i am getting the correct response.I am also setting the credentials to validate the xml request through angular code given below:-
*app.factory("soapService", ['$soap',function($soap){
var base_url = "http://10.75.108.90:61001/SOAPRouterServlet/?javaBean=true";
$soap.setCredentials("ORWFMT01","******");
return {
GetUsers: function(){
return $soap.post(base_url,"enterNotesForJob",{"destination": "AT", "pck": "PCK<01069JobManagement123Clientuserid2001071912345678BT-0000000001339","callerId":"sss","besUserId":"*******","channel":"ORSI","jobNo":"GBB02001","e2EData":""});
}
}
}]);*
I am following this link for referral angular soap example

Related

AngularJS header returns 500 Internal Server Error from Webapi

I am trying to pass a custom header to the webapi post method from my angularjs app. But it seems that webapi is not capturing the header information returning null to the request.
I have
$http.defaults.headers.common.Authorization = "xasdfYer3444";
in the app.js run method.
The request is as follows
getAuthInfo: function (username, password,demographics) {
var dataObj= {username:username,password:password};
var getservice = $resource(baselocation + "api/account", null);
return getservice.save(dataObj);
In the web api I have
public IHttpActionResult index(HttpRequestMessage req,AccountParams acct)
{
_accountinfo.request = req;
return Ok(_accountinfo);
}
It returns 500 Internal server error. Can anybody figure out what I am missing? Thanks.

return json response from spring mvc to a html/angular view

I have a html/angular view which needs to get data from spring mvc controller which returns Json response.
Previously I used angular, getting json calling a REST url.
Not sure how to do the same when spring mvc controller returns a json response.
Thanks.
My sample code.
js
function sendMessage(message) {
$.ajax({
url : "/sample/push/" + message,
processData : false,
contentType : "text/html; charset=utf-8",
type : 'POST',
success : function(response) {
// get response
},
error : function(request, status, error) {
},
});
}`
controller
#RequestMapping(value = "/push/{message}")
public #ResponseBody String processResult(#PathVariable String message) {
// "your json String"
return pushService.pushMessage(message);
}
ajax call and spring MVC tutorial - link : this tutorial XD
Keep in mind some concepts as partial view, angular controller, angular service and how to make async call using the $http angular service.
Basically you create a Controller (js), a Service (js) and a partial View (html)
In the service you implement all data logic and rest api calls
In the controller you manipulate data retrieved using the service and prepare it to be presented in the partials
In the partial you "bind" (and it is shown to the user all data, actions, etc) the info in the controller

Angular $http.get - retrieve data from url with authentication

Using Ajax in Angular I want to get some data from a URL that needs authentication. The curl command for getting this data outside of ajax is:
curl -u some_username:password 'https://website.com'
This is my function:
function getCurlData() {
window.btoa("some_username:password");
return $http.get("https://website.com").success( function(data) {
console.log(data);
}).catch(function() {
console.log("failed");
});
However I get a 403 forbidden message upon using this function. How can I retrieve the data?

access web services with angularjs

$scope.url = "http://localhost/MerchantProgramService.svc/GetMerchantProfile";
myXHRService.getData($scope.url).then(function(data) {
alert(data);
var xhrData = angular.fromJson(data);
// $scope.xhrData = xhrData.data.children;
});
I am trying to access web services with angularjs and i am failed to do it as i am new to angular.
POST http://localhost/MerchantProgramService.svc/GetMerchantProfile 404 (Not Found)
i am getting this error in console. i am using google chorme and using CORS extension to Access cross origin.

Web API loads via URL but get Error 404 from Angular script

I have a WebAPI method here:
http://localhost:50463/api/movies
and when accessing it from a browser it loads perfectly.
In my project (the same project as where Web API resides) when calling the method from AngularJS I get an error 500:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
When I click the link in the error it loads the data perfectly.
The routing for WebAPI is as follows:
config.Routes.MapHttpRoute("DefaultApiGet", "Api/{controller}",
new {action = "Get"},
new {httpMethod = new HttpMethodConstraint(HttpMethod.Get)}
);
This is the angular call
app.factory('dataFactory', function ($http) {
var factory = {};
factory.data = function (callback) {
$http.get('/api/movies').success(callback);
};
return factory;
});
I added this javascript just to rule-out angular, I get the same:
$.ajax({
url: "/api/movies",
type: 'GET',
//data: "{ 'ID': " + id + "}",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
Any idea what I have done wrong?
I assume your Web API and AngularJS app are running on a different port. In this case you are running in a Same-Origin-Policy issue.
Ensure your Web API is responding with HTTP CORS headers e.g.:
Access-Control-Allow-Origin: http://<angular_domain>:<angular_port>
or
Access-Control-Allow-Origin: *
Doesn't look like a CORS issue to me as you are using a relative URL in your $.ajax() request.
Did you try $.getJSON("/api/movies").then(successHandler, faulureHandler)
Not sure of that will help but for one you are sending a contentType header with a GET request which contains no content. There should be an Accept header instead, but WebAPI should be fine without one.
I would also remove the constrains from the routing and revert back to the default route mapping to see if the problem is there.
config.Routes.MapHttpRoute("DefaultApi",
"api/{controller}/{id}",
new {id = RouteParameter.Optional});

Resources