Vuejs soap client - soap

I'm considering moving a project to Vuejs and I have a lot of .net soap webservices already created and tested. I know that I can use axios to interact with REST webservices, but can i consume the .net soap webservices from vue ? I already serch and I can't find anything that fits... any idea ?
Basically I need to replace this code without use jquery:
$.ajax({type: 'POST', url: webservice_url , data: data_to_send,
contentType: 'application/json; charset=utf-8', dataType: 'json',
success: function (response) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});

Yes, you can interact with Soap from Vue via Axios.
Your code will look like this:
axios({
method: 'post',
url: webservice_url,
data: data_to_send
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
https://github.com/axios/axios - axios documentation with extended examples and good example with SOAP is this link:
https://stackoverflow.com/a/49153096/5808830

Related

Axios from browser not working but working from server

I am using node.js and express to buil my server.
I have some routes from where I'm using axios without problem:
(axios instaled with npm i axios)
const axios=require('axios');
const modelset=await axios({
method: 'get',
url:`https://developer.api.autodesk.com/bim360/modelset/v3/containers/${prIdSandbox}/modelsets`,
headers: {
'Authorization': `Bearer ${internalToken.access_token}`,
},
})
.catch(function(err) {
console.log(err)
})
.then(function(res) {
return res.data.modelSets[0].modelSetId;
})
Also I've using axios from a script loaded into my html page:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="js/ForgeTree.js"></script>
And the ForgeTree.js
const resources=await axios({
method: 'get',
url:`/api/forge/getDocuments/${containerId}/${modelSetId}/${version}`,
})
.catch(function(err) {
/* error in getting data */
console.log(err)
})
...
It has been working, but suddenly it fails:
ForgeTree.js:139 Uncaught (in promise) TypeError: axios is not a function
at getViewableModels (ForgeTree.js:139:27)
at HTMLDivElement.<anonymous> (ForgeTree.js:181:3)
at HTMLDivElement.dispatch (jquery.min.js:2:43064)
at v.handle (jquery.min.js:2:41048)
at Object.trigger (jquery.min.js:2:71515)
at S.fn.init.triggerHandler (jquery.min.js:2:72194)
at a.jstree.plugins.sort.trigger (jstree.min.js:2:12286)
at a.jstree.plugins.sort.activate_node (jstree.min.js:3:12893)
at a.jstree.plugins.sort.<anonymous> (jstree.min.js:2:8477)
at HTMLAnchorElement.i (jquery.min.js:2:88757)
It looks like if I have lost axios in the browser...could some one help?
Change
const axios=require('axios');
to
const axios=require('axios').default;
It's major change for Axios 1.0 or you can change library path to https://unpkg.com/axios#0.27.2/dist/axios.min.js to use like it's use to.
It has been fixed without doing anything...stop working for one day...

Retrieving params with sinatra on form submit. Params is undefined

I am having trouble accessing params in Sinatra after submitting a form. This is my form:
function submitForm(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '/mix_addresses',
//grab the inputs from address_section
//data: $('.add_address_section .add_address_field').map(function() { return $(this).val() }),
data: [1,2,3],
dataType: "json",
success: function(data) {
debugger;
}
});
}
And this is my endpoint:
require 'sinatra'
require 'jobcoin_client'
get '/' do
erb :add_coins
end
post '/mix_addresses' do
puts params
end
I'm getting to the endpoint, but the params are blank. Shouldn't it be [1,2,3]? Instead, it's:
{"undefined"=>""}
Anyone see what I'm doing wrong?
Several issues here :)
Sinatra configuration
Main problem is coming from the fact that Sinatra doesn't deal with JSON payloads by default. If you want to send a JSON payload, then the easiest solution will be :
To add rack-contrib to your Gemfile,
Then, require it in your sinatra app: require rack/contrib
And load the middleware that deals with this issue: use Rack::PostBodyContentTypeParser
And you should be good to go!
Source: several SO post reference this issue, here, here or here for instance.
jQuery ajax call
Also, note that there might be some issues with your request :
You'll need to use a key: value format for your JSON payload: { values: [1,2,3] }
You'll need to stringify your JSON payload before sending it: data: JSON.stringify( ... )
You'll need to set the request content type to application/json (dataType is related to the data returned by the server, and doesn't say anything about your request format, see jQuery ajax documentation for more details).
Eventually, you should end up with something like this on the client side:
function submitForm(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '/mix_addresses',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify({ values: [1,2,3] }),
success: function(data) {
debugger;
}
});
}

Good starting point for calling api in ionic framework

I am new in ionic framework so i don't have much idea. I want to know that how do i call api using ionic in my app? please anybody have any idea then suggest me.
Integrating a API Service with AngularJS in Ionic
angular.module('ionicApp', [])
.controller('MainCtrl', function($scope, $http) {
$http.get('https://cors-test.appspot.com/test').then(function(resp) {
console.log('Success', resp);
// For JSON responses, resp.data contains the result
}, function(err) {
console.error('ERR', err);
// err.status will contain the status code
})
})
More...
angular.module('ionicApp', [])
.controller('MainCtrl', function($scope, $http) {
$http({
method: method,//GET/POST/DELETE
url: url,
data: data,//JSON DATA FOR POST
dataType: 'json',
headers: {
"Content-Type": "application/json"
}
}).success(function (data) {//Success handling
console.log(data);
}).error(function (data, status) {//Error handling
console.log(status + data);
});
)}
Above method works for any type of HTTP(Get/Post/Delete/Put) request.
Regards

Logout user with services not working

I am working on a mobile app which I will be deploying using Phonegap.
Now I am able to login using Drupal 7 services and I am also getting the session name and session id. But I am not able to Logout the user. When even I am doing that.. I see this issue on my chrome console: 406 (Not Acceptable:)
I tried sending headers as "Cookie" then "sessionname=sessionid" format.. but that didn't work. Can someone please suggest a way.
You need to add the CSRF token from YOUR_SITE/services/session/token, and then add it to the header in the same way you added the Cookie, something like
'X-CSRF-Token: ' + $token
And make sure it's PUT, there is a nice example here:
http://pastebin.com/N35SN7Xj
The relevant section looks like this:
$.ajax({
url: "http://your_url/endpoint/user/logout.json",
type: 'post',
dataType: 'json',
beforeSend: function (request) {
request.setRequestHeader("X-CSRF-Token", token);
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Failed to logout');
alert(JSON.stringify(jqXHR));
alert(JSON.stringify(textStatus));
alert(JSON.stringify(errorThrown));
},
success: function (data) {
alert("You have been logged out.");
}
});
This works for me.
$http({
method: 'POST',
url: drupal_instance + api_endpoint + 'user/logout',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'X-CSRF-Token': user.token
}
})
.success(function (data, status, headers, config) {
alert('Success');
})
.error(function (data, status, headers, config) {
alert('Error');
});

Promise response works with GET, but not with POST in XHR

I am trying to call a URL through XHR.post on the DOJO 1.8. I need catch the STATUS property and getHeader() from promise response, but the problem is, when I call my URL with POST I don't have any promise, and when I call with GET I have all properties that I need, but I only can send the request as POST.
The most strange is that I have another code in AngularJS which works well, this code does the same thing. I am testing DOJO and AngularJS.
I need catch the STATUS information to check if it is 201(created), if true I need catch getHeader('location') and call the URL that I picked up from getHeader('location').
Look at my method in Dojo 1.8:
checkCreation: function(typeFile, id){
var promise = xhr('/rest/list/one', {
handleAs: 'json',
method: 'post',
accepts: 'application/json',
headers: {
Accept: 'application/json',
id: id,
type: typeFile
}
});
promise.response.then(function(response) {
console.log("status", response.status);
console.log("options", response.options);
console.log("url", response.url);
console.log("timestamp", response.options.timestamp);
console.log(response);
});
},
I discovered the problem, I commented the lines followings and now works fine.
//handleAs: 'json',
//accepts: 'application/json',
The handleAs you need to use only when you have a JSON response. About "accepts" I haven't found what difference between "accept" and "Accept"(inside headers) yet.
Now I can take my informations:
console.log('location: ', response.getHeader('location'));
console.log("status: ", response.status);