The following Ruby code loads a Discovery probe message from a file and send it as multicast udp message to the discovery proxy address
require "socket"
require "ipaddr"
MULTICAST_ADDR = "239.255.255.250"
PORT = 3702
def get_file_as_string(filename)
data = ''
f = File.open(filename, "r")
f.each_line do |line|
data += line
end
return data
end
def SendDiscoveryProbeMsg (pMsg)
socket = UDPSocket.open
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_TTL, 10)
socket.send(pMsg, 0, MULTICAST_ADDR, PORT)
socket.close
end
theTemplateTxt = get_file_as_string 'DescoveryProbeTemplate.xml'
puts theTemplateTxt
SendDiscoveryProbeMsg theTemplateTxt
The Message is :
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Probe</a:Action>
<a:MessageID>urn:uuid:4faf9212-2449-43bd-9cfb-9cf8b12300d1</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01</a:To>
</s:Header>
<s:Body>
<Probe xmlns="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01">
<d:Types xmlns:d="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01" xmlns:dp0="http://Microsoft.Samples.Discovery">dp0:ICalculatorService</d:Types>
<Duration xmlns="http://schemas.microsoft.com/ws/2008/06/discovery">PT5S</Duration>
</Probe>
</s:Body>
</s:Envelope>
אין תגובות:
הוסף רשומת תגובה