Main Site Documentation

Project - DPWS Discovery demo for the Hello World sample project


#1

I just posted DPWS Discovery demo for the Hello World sample project on Codeshare. Feel free to discuss and make suggestions here.


#2

DPWS will always benefit from more examples, thanks


#3

@ NickP - I am trying to open the code with VS2010 but I’m getting problems. Isn’t it possible open it with this version?


#4

Getting discovery and announcements to work properly needed the new April 25th package. Whilst I believe it is possible to use VS2010, it is not supported so this is a VS2012 solution.


#5

@ NickP - So, is there no way to run you project in VS2010?

Could you please run your DPWS HelloWorld Server on the Gadgeteer and try to discover it and its services with this software (http://ws4d.e-technik.uni-rostock.de/dpws-explorer/)? It s a very simple program, don’t need to install anything.

I’m driving myself mad trying to build a DPWS scenario and I get errors everytime and I don’t know if the mistake is in my code or in the Gadgeteer.

Thank you in advance.


#6

@ fprado Yes dpws-explorer does find the device. It does not find metadata though because mex is not configured in the sample.

device types: {http://schemas.example.org/HelloWCF}HelloWCFDeviceType
{http://docs.oasis-open.org/ws-dd/ns/dpws/2009/01}Device

endpoint references urn:uuid:18571766-87df-06e2-bb68-5136c48f483f

XAddresses address=http://192.168.5.191:8084/18571766-87df-06e2-bb68-5136c48f483f, ProtocolInfo: DPWSProtocolVersion [dpwsVersion=0]


#7

@ NickP - Thank you very much.

What is mex? How can I configure it?


#8

@ andre.m - Could you provide some code sample to see how it works? I am traying to make discoverable a DPWS service running on a Gadgeteer (MicroFramework 4.2) but I can not find the right way to do it.

In the HelloWorldServer_WCF code example there is some code, but it isn’t present in the HelloWorldServer_MF sample, which is, at the end, the one I’m using.

            ServiceHost serviceHost = new ServiceHost(typeof(ServiceHelloWCF), baseAddress);
            try
            {
                Binding binding;
                DiscoveryVersion ver;

                ver = DiscoveryVersion.WSDiscovery11;
                binding = new WSHttpBinding(SecurityMode.None);

                // To enable WSDiscoveryApril2005 and Soap12WSAddressingAugust2004
                ver = DiscoveryVersion.WSDiscoveryApril2005;
                binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.Soap12WSAddressingAugust2004, Encoding.UTF8), new HttpTransportBindingElement());
   
                ServiceEndpoint wsEndpoint = serviceHost.AddServiceEndpoint(typeof(IServiceHelloWCF), binding, "");
                EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior();

                // Add the discovery behavior to the endpoint.
                wsEndpoint.Behaviors.Add(endpointDiscoveryBehavior);
                
                // Make the service discoverable over UDP multicast
                ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();
                // Announce the availability of the service over UDP multicast
                serviceDiscoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint(ver));
                // Make the service discoverable over UDP multicast.
                serviceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);
                serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint(ver));
                // Announce the availability of the service over UDP multicast


                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.HttpGetUrl = baseAddress;
                serviceHost.Description.Behaviors.Add(smb);

Any help?


#9

Up! Please help with the mex configuration (code, if possible) in order to allow DPWS metadata and hosting services to be discovered. I’m a little bit lost with the .NET MF documentation.


#10

Sorry, you’ve probably exceeded the knowledge of 93.4% of forum watchers, as DPWS is not a very often used feature


#11

@ Brett - Hi Brett, thanks for answering.

For sure I do not exceed that knowledge because I’m green with .NETMF and Gadgeteers and I know that featue is rarely used but maybe experienced users like @ andre.m or @ NickP that have played a little bit more with DPWS can give a hand (one more) :slight_smile:


#12

@ fprado

DPWs services are discoverable by default. I believe the issue you are facing is that the standard 4.2 release doesn’t support UDP multicast which is a pre-requisite for discovery. You have to use the April 25th sdk release which fixes the UDP issue. Someone please correct me if I am wrong but I think you end up using the 4.2 library from the 4.3 MF release.

The “_MF” sample is based on DPWS which has discovery turned on by default. (You turn it off by setting Device.SupressAdhoc to true);

The “_WCF” sample is based on Windows Communication Framework. WCF is used for a much broader range of situations which don’t usually require discovery so the DiscoveryBehavior has to be added explicitly.

I have to take back my earlier comment about MEX not being configured; MEX is enabled by default when you call Device.Initialize. I am not sure why the dpws-explorer tool couldn’t find the MEX endpoint but the WCF client does find it.


#13

@ NickP - Thank you very much for your answer.

So, I didn’t understand well your last comment (https://www.ghielectronics.com/community/forum/topic?id=12223&page=1#msg125716)

So, could DPWS-Explorer get the device and services metadata in your code by default? Because mine didn’t work.

I’m also in touch with the people of DPWS-Explorer and I show them the log files I got when I tried to discover DPWS running on a Gadgeteer using DPWS Explorer (reminder: I can discover and see the device -hosting service- but I’m not able to discover the hosted services). They told me: The error is, that your device does not respond with a GetResponse.(http://sourceforge.net/p/ws4d-javame/discussion/664431/thread/22d53a7a/)

Right now I’m using the last April 25th SDK in MF4.2 in VS2010. I’m sorry but I am also confused about “the 4.2 library from the 4.3 MF release.” Anyway I think I’m running the last SDK with multicast fixed but maybe that’s the problem.

I know I’m a pain in the ass with this issue but you are the only people in the whole internet I can ask :slight_smile: So, if you still can give some ideas, help, support you’ll make me happy.


#14

The GHI SDK is from 1st May (the filename has 30th April) so I think you’re a week out ! And yes I think the multicast fix was a late confirmed fix… https://www.ghielectronics.com/support/.net-micro-framework


#15

@ fprado

I was incorrect about MEX not being configured. Having looked at the source code, MEX IS configured out of the box with DPWS.

dpws-explorer could not get the metadata as DPWS returned a soap fault when probed. I will have to set up a wire trace and examine the soap message to see what went wrong.

That said, you do not need MEX to discover your service. The preferred discovery method is to use a probe and I can confirm that probes work.

In the demo I uploaded, the ServiceDiscoveryManager cless will find any DPWS service (host or hosted) using a probe.

In summary the steps to find a service of type ServiceInterface are in the following snippet:



Log("Starting probe for " + typeof(ServiceInterface).ToString());

FindCriteria ServiceFindCriteria = new FindCriteria(typeof(ServiceInterface));

var endPoint = new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscovery11);

//http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c08c55c6-784a-4896-abfa-ea5299a03cfa
//http://support.microsoft.com/kb/2777305
endPoint.Behaviors.Add(new WorkaroundBehavior());

DiscoveryClient discoveryClient = new DiscoveryClient(endPoint);

Collection<EndpointDiscoveryMetadata> services = discoveryClient.Find(ServiceFindCriteria).Endpoints;

discoveryClient.Close();

if (services.Count != 0)
{
     Log("   service found: " + services[0].Address.ToString());
                    return services[0].ListenUris[0];
}
else
{
      Log("   no service found");
      //       if (announcementsInProgress) SetupAnnouncementService();
      return null;
 }



#16

@ NickP - So, you get the same error with soap fault with the DPWS Explorer, right? Please let me know if you figure out something about this.

The problem is that I want to use clients running no .NET code but other libraries (in concrete JMEDS for Java, the one DPWS-Explorer is based on) with a DPWS server in a Gadgeteer.

Anyway, I can not run your HelloWorldClientWCF: error with the incorrect references projects (DPWSDiscoveryManager and HelloWorldClientWCF) in DemoClient. How can I re-add them?

@ Brett Thanks for the info. Anyway, I think I was wrong and I’m using the last SDK you mentioned.


#17

@ fprado Yes I get the soap fault with DPWS explorer. Digging into the code, the DPWS MEX service on the gadgeteer is throwing a null reference exception because the GET request from dpws-explorer is not sending a replyto header.

This is technically an optional field so should be reported as a bug.

[quote]/wsa:ReplyTo
This OPTIONAL element (of type wsa:EndpointReferenceType) provides the value for the [reply endpoint] property. If this element is NOT present then the value of the [address] property of the [reply endpoint] EPR is “http://www.w3.org/2005/08/addressing/anonymous”.[/quote]

There may be a way to get JMEDS to add this header; I haven’t found a use for MEX so I’m not familiar with it.

[quote]
Anyway, I can not run your HelloWorldClientWCF: error with the incorrect references projects (DPWSDiscoveryManager and HelloWorldClientWCF) in DemoClient. How can I re-add them?[/quote]

open the two projects in the same solution: right click the solution -> add ->existing project…

then add the references: right click on the HelloWorldClientWCF project -> add reference -> choose the projects tab


#18

Please vote for the fix to MEX:


#19

hi admin,
Please upload the WSDL file for the project (HelloWorldServerGadgeteer).
In my project, the fez raptor acts as WCF Server. In Slot1 of , i have connected the enc28 ethernet module.
now i want to run WCF client on a different machine.
I need WSDL file to know the end points in the format http://<ip_address:port>/uuid


#20

Hi Shailendra

The easiest way to get the WSDL is to run the Samples\HelloWorldServer_WCF sample and browse to the uri published and append ?singleWsdl
E.g. (for me) http://192.168.5.44:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D?singleWsdl

Obviously your ip addresses would be different.

Alternatively look at the code share I uploaded that has a complete solution configuring the endpoints via discovery here: https://www.ghielectronics.com/community/codeshare/entry/736

Nick