使用cxf自带的API获取多播获取服务时,获取不到。
换成google的可以通过多播发现服务
// Uncomment the following to override the IP this server will announce itself at
// if proxy mode is enabled. This IP is only used if server.enableProxyMode() is called.
// WsDiscoveryConstants.proxyAddress = InetAddress.getByName("10.0.1.3");
// Uncomment the following to bind multicasts to a specific interface
// WsDiscoveryConstants.multicastInterface = NetworkInterface.getByInetAddress(InetAddress.getByName("10.0.1.4"));
// Create a new server instance
WsDiscoveryServer server = WsDiscoveryBuilder.createServer();
// Start background threads
server.start();
System.out.println("Sending probe...");
// Send Probe-message.
server.probe();
// All listening WS-Discovery instances should respond to a blank probe.
// The background server will receive the replies and store the
// discovered services in a service directory.
System.out.println("Waiting for replies. (2 sec)");
Thread.sleep(2000);
// Check if any of the discovered services are missing XAddrs (invocation address).
// If they are, try to resolve it.
{
// Get a copy of the remote service directory
IWsDiscoveryServiceCollection result = server.getServiceDirectory().matchAll();
boolean resolve_sent = false;
for (WsDiscoveryService service : result)
// Is XAddrs empty?
if (service.getXAddrs().size() == 0) {
// Send Resolve-message
System.out.println("Trying to resolve XAddr for service " +service.getEndpointReference());
server.resolve(service);
resolve_sent = true;
}
if (resolve_sent) {
System.out.println("Waiting for ResolveMatches. (2 sec)");
Thread.sleep(2000);
}
}
// Get a copy of the remote service directory and display the results.
{
System.out.println("** Discovered services: **");
IWsDiscoveryServiceCollection result = server.getServiceDirectory().matchAll();
for (WsDiscoveryService service : result) {
// Print service info
System.out.println(ToStringBuilder.reflectionToString(service,ToStringStyle.MULTI_LINE_STYLE));
System.out.println("---");
}
}
换成google的可以通过多播发现服务
// Uncomment the following to override the IP this server will announce itself at
// if proxy mode is enabled. This IP is only used if server.enableProxyMode() is called.
// WsDiscoveryConstants.proxyAddress = InetAddress.getByName("10.0.1.3");
// Uncomment the following to bind multicasts to a specific interface
// WsDiscoveryConstants.multicastInterface = NetworkInterface.getByInetAddress(InetAddress.getByName("10.0.1.4"));
// Create a new server instance
WsDiscoveryServer server = WsDiscoveryBuilder.createServer();
// Start background threads
server.start();
System.out.println("Sending probe...");
// Send Probe-message.
server.probe();
// All listening WS-Discovery instances should respond to a blank probe.
// The background server will receive the replies and store the
// discovered services in a service directory.
System.out.println("Waiting for replies. (2 sec)");
Thread.sleep(2000);
// Check if any of the discovered services are missing XAddrs (invocation address).
// If they are, try to resolve it.
{
// Get a copy of the remote service directory
IWsDiscoveryServiceCollection result = server.getServiceDirectory().matchAll();
boolean resolve_sent = false;
for (WsDiscoveryService service : result)
// Is XAddrs empty?
if (service.getXAddrs().size() == 0) {
// Send Resolve-message
System.out.println("Trying to resolve XAddr for service " +service.getEndpointReference());
server.resolve(service);
resolve_sent = true;
}
if (resolve_sent) {
System.out.println("Waiting for ResolveMatches. (2 sec)");
Thread.sleep(2000);
}
}
// Get a copy of the remote service directory and display the results.
{
System.out.println("** Discovered services: **");
IWsDiscoveryServiceCollection result = server.getServiceDirectory().matchAll();
for (WsDiscoveryService service : result) {
// Print service info
System.out.println(ToStringBuilder.reflectionToString(service,ToStringStyle.MULTI_LINE_STYLE));
System.out.println("---");
}
}