|
Let this be the webmethod:
<br />
<webmethod()> _<br />
Public Function HelloWorld() As String<br />
Return "Hello World"<br />
End Function<br />
I have a test harness which is a windows form and I would like to send a request and receive a repsonse asynchronoulsy. Please help me with the code asap.
Thank you
|
|
|
|
|
dreddy7 wrote: the code asap
Not the way it works around here.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Sorry I did not understand!
|
|
|
|
|
People don't just hand over code when someone needs it urgently or right away.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I am not asking people to do it right away keeping their work aside. People who cant help need not bother at all and better be off. I am asking only those who have already worked on it and who can guide me in the right direction.
|
|
|
|
|
dreddy7 wrote: I am asking only those who have already worked on it and who can guide me in the right direction.
I did some web services stuff the other day, investigating how to consume web services through a silverlight app.
Have you made a reference to the web service in your project?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I have added it as the web reference to my windows app project and created an instance of it to call the web methods.
|
|
|
|
|
Ok. What code have you done in your windows app to create the instance and method call? Sounds like you are so far on the right track.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
This may be silly, but do you have the web service running?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Yeah the web service is running...I am actually new to web services. So, is there any way to confirm if it is actually running or not. And the code that I have on my Windows app is a simple one for now.
On a button click event , it just says:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Cool is the name of my webservice
Dim objService as New Cool.Service
TextBox1.Text = objService.HelloWorld()
end sub
And the web method in the Cool Service is:
<webmethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
Now what is an asynchronous web request-response? I have the following method which does a httpwebrequest-httpwebresponse:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myHttpWebRequest As HttpWebRequest
Dim myHttpWebResponse As HttpWebResponse
Dim receiveStream As Stream
Dim encode As Encoding
Dim sr As IO.StreamReader
Dim strUrl As String = "http://localhost:5404/CoolService/Service.asmx"
Try
myHttpWebRequest = CType(WebRequest.Create(strUrl), HttpWebRequest)
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
receiveStream = myHttpWebResponse.GetResponseStream()
encode = System.Text.Encoding.GetEncoding("utf-8")
sr = New StreamReader(receiveStream, encode)
Do Until sr.Peek = -1
TextBox2.Text += sr.ReadLine
Loop
Catch ex As System.Net.WebException
MsgBox(ex.Message)
Finally
sr.Close()
myHttpWebResponse.Close()
End Try
End Sub
Is this asynchronous?
|
|
|
|
|
dreddy7 wrote: .I am actually new to web services.
Same here, and have picked up on it relatively quickly. For future reference, put your code inside the code block or inline code tags at the bottom of the reply form. It makes it easier to read
dreddy7 wrote: the code that I have on my Windows app is a simple one for now.
At least you are not dealing with passing xml right now like I am trying to do. My case works sort of okay but even though I am returning XmlDocument , my test app is looking for XmlElement . Now, set aside my banter, back to your problem....
Dim strUrl As String = "http://localhost:5404/CoolService/Service.asmx" , I took out CoolService, and left it as Dim strUrl As String = "http://localhost:5404/Service.asmx" and it looks like it worked.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Wow...thats great! Actually I need to pass an xmlDoc and receive an ID in response to it from the webservice. But what I am thinking is, if I get this simple one to work...we can definetely replace the strings with whatever we want. Am I making sense?
Can you please discuss more on making asynchronous calls?
|
|
|
|
|
dreddy7 wrote: Actually I need to pass an xmlDoc and receive an ID in response to it from the webservice.
It's not that tough actually.
dreddy7 wrote: Can you please discuss more on making asynchronous calls?
I've stuck with just invoking the method, here is what I've done, minus any client intellectual property...
<webmethod()> _
Public Function GetContact(ByVal contactID As Integer) As XmlDocument
Dim ContactDataSet As New ContactDataSet
Dim ContactDataAdapter As New ContactDataSetTableAdapters.ContactTableAdapter
ContactDataAdapter.FillByID(ContactDataSet.ContactTable, contactID)
Dim memStream As New System.IO.MemoryStream
Dim xml As New XmlTextWriter(memStream, System.Text.Encoding.UTF8)
ContactDataSet.ContactTable.WriteXml(xml)
Dim myXDoc As New XmlDocument()
memStream.Flush()
memStream.Position = 0
myXDoc.Load(memStream)
Return myXDoc
End Function
It very happily gags up the correct data.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Here is a Google search [^] I am going to look through.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Well, disregard my latest post, it only gave back the entire http response. You may have to hand pick out the returned value out of the http response, perhaps through regular expressions.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I am automating excel and would like to align the lefts of my VB.NET form and Excel application. Unfortunately, the "left" in Excel is on a different scale than the "left" of the windows forms. I would like to use code like:
Me.Left = oApp.Left
where oApp refers to the Excel application. This, however, fails to left align these windows. I think I'm missing the big picture here. Anyone have any suggestions? Thanks!
- Craig
"That rug really tied the room together."
|
|
|
|
|
Yep, you're missing it alright. The Left in the Excel.Application class is not in pixels, but in points. Documentation on Left[^]...
|
|
|
|
|
I see... So that means there isn't a good way to do what I want to do?
"That rug really tied the room together."
|
|
|
|
|
erhmmm converting points to pixels or if it's out of hand using the old fashion GetWindowEx and GetWindowRect from the Win32 API.
An aproximation is 1.3 ... so for let's say 3 points u have about 3,9 pixels.
|
|
|
|
|
I didn't say that. It just means you have to use a different method to get the window rectangle. Use the Process class to find the EXCEL process, the get it's MainWindowHandle. You can then use that handle to call Win32's GetWindowRect function (see www.pinvoke.net for examples) to get the Left position in pixels.
|
|
|
|
|
Good afternoon!
Currently i'm working with .Net Framework 2.0 SerialPort Class and trying to send a bunch of bytes as a command to obtain data from a remote system.
The GSM connection is well done, but after this connection, i'm sending a command regarding the communication protocol of the remote equipment, but i don't get any kind of response.
Could anyone help me with this? I'm sending the code i've wrote:
Option Explicit On
Option Strict Off
Imports System.IO.Ports
Public Class Form1
Public Delegate Sub StringSubPointer(ByVal Buffer As String)
Dim WithEvents spObject As New SerialPort
Dim Test_Command As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.BackColor = Color.Silver
Button2.BackColor = Color.Silver
Button3.BackColor = Color.Silver
With spObject
.PortName = "COM6"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.DtrEnable = True
.RtsEnable = True
'.ReadTimeout = 12000
'.NewLine = Chr(13) 'CR - Carriage Return
'.Encoding = System.Text.Encoding.GetEncoding(28591)
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If spObject.IsOpen Then
spObject.Close()
End If
Try
spObject.Open()
Catch ex As Exception
MsgBox("It wasn't possible to open your Serial Com Port! Please try again...", MsgBoxStyle.OkOnly, "Warning")
Return
End Try
Try
spObject.Write("+++" + vbCr)
spObject.Write("ATDPhoneNumber" + vbCr)
RichTextBox1.Clear()
RichTextBox1.Text = "Dialing with the Remote System... Please wait for a few seconds..."
Catch ex As Exception
MsgBox("It wasn't possible to connect with the Remote System! Please try again...", MsgBoxStyle.OkOnly, "Warning")
Return
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.BackColor = Color.Silver
Button2.BackColor = Color.Green
Dim btArray As Byte() = {68, 00, 00, 68, 00, 00, 00, 00, 80, 00, 01, 81, 00, 16}
Try
spObject.Write(btArray, 0, 14)
RichTextBox1.Clear()
RichTextBox1.Text = "Your command has been correctly sent. Please standby for data response..."
Catch ex As Exception
Button2.BackColor = Color.Silver
MsgBox("Sorry, it wasn't possible to send your command. Please try again...", MsgBoxStyle.OkOnly, "Warning")
Return
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Button1.BackColor = Color.Silver
Button2.BackColor = Color.Silver
Button3.BackColor = Color.Green
RichTextBox1.Clear()
RichTextBox1.Text = "Disconnecting from the Remote System..."
Try
With spObject
.Write("+++" + vbCr)
.Write("ATH0" + vbCr)
End With
Catch ex As Exception
RichTextBox1.AppendText("It wasn't possible to disconnect from the Remote System. Please try again!")
Button3.BackColor = Color.Silver
Return
End Try
Try
With spObject
.Close()
End With
Catch ex As Exception
RichTextBox1.AppendText("It wasn't possible to close your communication port! Please try again.")
Button3.BackColor = Color.Silver
Return
End Try
Try
Me.Close()
Catch ex As Exception
RichTextBox1.Clear()
Button3.BackColor = Color.Silver
RichTextBox1.Text = "It wasn't possible to close this application! Please try again."
Return
End Try
End Sub
Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles spObject.DataReceived
Button2.BackColor = Color.Silver
Me.BeginInvoke(New StringSubPointer(AddressOf Display), spObject.ReadLine)
End Sub
Private Sub Display(ByVal Buffer As String)
RichTextBox1.AppendText(Buffer)
End Sub
End Class
Best Regards.
|
|
|
|
|
There are 3 glaring possibilities. The first is you have to make asolutely sure your communication parameters are correct, like baud rate, data bits, stop bits, parity, ....
The second is that you're call to spObject.ReadLine will only work if the device sent back what .NET interprets as a Newline[^] sequence in the byte stream. If this sequence isn't there, then the call will throw a Timeout exception.
The third possibility is that you didn't send the command to the device in a manner, or format, the device expects. Is the byte sequence correct?? Is the command terminated correctly?? Was it sent with extra bytes appended to it that the device didn't expect (like CR and LF)??
This is going to be a difficult question to answer because YOU have the hardware, not us. We have nothing to test this against. It's going to take a bunch of research on the device and trial-and-error fiddling on your part to get this to work.
|
|
|
|
|
Very good answer by Dave Kreskowiak
first check from the hyperterminal to check your sending protocal is correct,
after u got response then look through your code for bugs.
don't use the spobject.readline , this statement will not accept the extended ascii chart characters. use spobject.readbytes
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
Hi,
I have a string in which I have to replace all occurances of special characters with null string or character. Trim(Char[]) function is trimming only start and end of the string but I need to Trim the complete string between also.
Can anybody please help me.
Thanks
Aleem Mohammad.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
Use replace instead of trim.
Dim line As String = "abc#$*xyz"
line = Replace(line, "#$*", "")
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|