我正在尝试将CSTA-XML消息发送到电话服务器。我应该使用带有“ ECMA-323附录J.2”中指定的帧的TCP发送消息(另请参见https://blog.jonaskoeritz.de/2016/10/23/understanding-csta-part-1/)。无论我如何尝试设置消息,并且DataAvailable框架始终为false,响应为空。
完成学业后,我不再需要使用Web应用程序或进行任何其他需要使用TCP的操作,因此我的知识非常生锈。我不确定问题出在我如何发送消息或XML消息本身,所以我首先尝试确定我在发送消息时是否做错了什么。由于我完全没有响应,而是收到了错误消息,因此我以为是前者。
该服务器是Mitel MiVoice Office400。已激活CSTA,IP和端口正确,端口正在侦听,并且我要登录的用户具有CSTA许可证。我尝试发送各种XML字符串来启动会话,但从未从服务器得到任何反应。示例中的XML字符串只是我尝试过的众多变体之一。尽管考虑到我没有任何回应,但我假设问题是在更基本的层面上,而不是XML方面的问题。我从电话服务器手册中直接取出了XML字符串,并尝试了其服务器版本。
Private Function TestConnection(msg As String, Optional addDataFrame As
Boolean = True) As Boolean
Dim PBX_Port As Int32 = 1234
Dim PBX_IPAddress As IPAddress = IPAddress.Parse("192.168.1.111")
Using TCP_Client As New TcpClient()
Dim TCP_Encoder As New UTF8Encoding
TCP_Client.Connect(PBX_IPAddress, PBX_Port)
Using TCP_Stream As NetworkStream = TCP_Client.GetStream
Dim bytes(TCP_Client.ReceiveBufferSize) As Byte
Dim responseData As String = ""
If TCP_Stream.CanRead = False Then MsgBox("Can't read")
If TCP_Stream.CanWrite = False Then MsgBox("Can't write")
Dim Header As Byte() = BitConverter.GetBytes(0)
ReDim Preserve Header(2)
Dim InvokeID As Byte() = BitConverter.GetBytes(CInt(1))
ReDim Preserve InvokeID(4)
Dim MessageBody As Byte() = TCP_Encoder.GetBytes(msg)
Dim MessageLength As Byte() = BitConverter.GetBytes(Header.Length + InvokeID.Length + MessageBody.Length + 2) '2 = size of MessageLength field
ReDim Preserve MessageLength(2)
Dim Data As Byte()
If addDataFrame Then
Data = Combine(Header, MessageLength)
Data = Combine(Data, InvokeID)
Data = Combine(Data, MessageBody)
Else
Data = TCP_Encoder.GetBytes(msg)
End If
TCP_Stream.Write(Data, 0, Data.Length)
TCP_Stream.Flush()
'EDIT: Tried with and without flush and also tried adding Thread.Sleep(10000) here
If TCP_Stream.DataAvailable Then MsgBox("Data available")
TCP_Stream.Read(bytes, 0, CInt(TCP_Client.ReceiveBufferSize))
responseData = Encoding.UTF8.GetString(bytes)
If responseData = "" Then
Return False
Else
For Each b As Byte In bytes
If b.ToString <> "0" Then Return True
Next
Return False
End If
End Using
End Using
end function
Private Function Combine(first As Byte(), second As Byte()) As Byte()
Dim result(first.Length + second.Length - 1) As Byte
Buffer.BlockCopy(first, 0, result, 0, first.Length)
Buffer.BlockCopy(second, 0, result, first.Length, second.Length)
Return result
End Function
Dim msgStartApplication As String = <![CDATA[<?xml version="1.0" encoding="UTF-8">
<applicationInfo>
<applicationID>CSTA_Test</applicationID>
<applicationSpecificInfo>
<SessionLoginInfo xmlns="http://www.aastra.com/csta">
<userName xmlns="">xxx</userName>
<password xmlns="">xxx</password>
</SessionLoginInfo>
</applicationSpecificInfo>
</applicationInfo>
<requestedProtocolVersions>
<protocolVersion>http://www.ecma-international.org/standards/ecma-323/csta/ed5"</protocolVersion>
</requestedProtocolVersions>]]>.Value
TCP_Stream.DataAvailable始终为false。 ResponseData始终为空,或者如果我仍然尝试读取它,则仅包含零。我期待至少类似于错误消息。