Imports System
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<System.Web.Script.Services.ScriptService()>
<WebService(Namespace:="http://tempuri.org/")>
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Public Class WBS_Actions
Inherits System.Web.Services.WebService
<WebMethod()>
Public Sub TrackAction(byval sText as string)
Dim path As String = "c:\MyTest.txt"
Using fs As FileStream = File.Create(path)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(sText)
' Add some information to the file.
fs.Write(info, 0, info.Length)
End Using
End Sub
End Class
On anoter website, I have a JS that calls this webservice like this:
function ActionDone() {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:57358/WBS_Actions.asmx/TrackAction', true);
xhr.setRequestHeader('Content-type', 'text/plain');
xhr.send("test");
}
Now, the issue is that the file is not created with that code. Instead, if I changed the webservice to the code below, the file is created, but I am missing the option to send data from JS to the webservice.
Public Sub TrackAction()
Dim path As String = "c:\MyTest.txt"
Using fs As FileStream = File.Create(path)
Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is my text")
' Add some information to the file.
fs.Write(info, 0, info.Length)
End Using
End Sub
For your original method with parameter, I suggest you try code below:
$(document).ready(function () {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:61275/WBS_Actions.asmx/HelloWorld', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
console.log(xhr.responseText);
}
}
xhr.send("sText=" + 'test');
})
Best Regards,
Edward
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
function ActionDone() {
alert("test_0");
alert("test_1");
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:57358/WBS_Actions.asmx/TrackAction', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
alert("test_2");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
alert("test_3");
console.log(xhr.responseText);
}
}
xhr.send("sText=" + 'test');
}
Best Regards,
Edward
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
3 Posts
Call Webservice from JS, sending some data
Feb 13, 2018 11:29 PM|imendimu|LINK
hi,
I have a webservice created with asp, which is:
On anoter website, I have a JS that calls this webservice like this:
Now, the issue is that the file is not created with that code. Instead, if I changed the webservice to the code below, the file is created, but I am missing the option to send data from JS to the webservice.
Any help would be much appreciated, thanks!
imendimu
Contributor
3290 Points
1595 Posts
Re: Call Webservice from JS, sending some data
Feb 15, 2018 08:33 AM|Edward Z|LINK
Hi imendimu,
For your original method with parameter, I suggest you try code below:
Best Regards,
Edward
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
3 Posts
Re: Call Webservice from JS, sending some data
Feb 15, 2018 01:27 PM|imendimu|LINK
Hi,
Adding your suggested code to the function called in the onClick of the control, nothing happens.
Only the first alert("test_0"); is shown.
Just to remind that these are two different solutions, and I test them running both of them at the same time, obviously.
Thanks
Contributor
3290 Points
1595 Posts
Re: Call Webservice from JS, sending some data
Feb 19, 2018 01:23 PM|Edward Z|LINK
Hi,
I suggest you make a test with code below:
Best Regards,
Edward
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
1 Points
3 Posts
Re: Call Webservice from JS, sending some data
Feb 19, 2018 03:10 PM|imendimu|LINK
That works! Many thanks!