Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

Call Webservice from JS, sending some data

$
0
0

hi,

I have a webservice created with asp, which is:

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

Any help would be much appreciated, thanks!

imendimu


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>