DPWS device host with WCF client

As the subject indicates, I’m trying to implement a DPWS service on my device to serve as a web services host, with a client application running on the PC. I’m afraid I may have bitten off more than I can chew as I have never done any web services development and am learning several different technologies at the same time. I’ve hit a wall and I’m hoping someone can help me out by at least hinting where I can look for help next.

I started with a fairly basic WSDL file. It defines two complex types: one empty for client queries, and one wrapping an integer. They are used by two simple messages: value request and value response, respectively. Then I have portType, binding, and service elements defined. Everything trying to be as simple as possible.

On the device side, I ran the WSDL file through MfSvcUtil.exe to generate my service.cs, clientproxy.cs and hostedservice.cs files. All of these files are wrapped into a separate library. In the application, I followed the SimpleService example pattern by generating service implementation object and an additional simple device host object. This all seems to work sufficiently well. When I start up my device, I can see the web services host show up under my Windows 7 networking display. Properties on it correctly display the values I entered in my application.

For the client side, I took the same WSDL file and ran it through SvcUtil.exe. This generated my client side code in form of a generatedProxy.cs and app.config files. I configured everything as best as I could and upon running my client, I do get a connection, but my host throws an exception. Apparently, my WCF client app does not put a soap header into the request, while the host requires it.

I’ve read up a bunch on contracts and headers and such, but there are two things that stump me. One, it seems that the dpws host requires a specific header that general MessageHeader type does not support through its exposed attributes. And secondly, I would like to do this automatically. From what I can figure out, dpws host expects an auto generated header that it then returns back to the client in its own message.

How would I go about setting up my WSDL file to force WCF to auto-generate the appropriate headers for my DPWS host?

–Edit–
I didn’t want to upload any code, because there is a lot of it. But if it would help for me to upload any specific code segments, please ask.

This is the lease documented and used feature in netmf. It would be great to see some more docs and tutorials.

LOL! I agree Gus! :slight_smile:

I’d be glad to put up some words and code on it, as soon as I successfully transfer data from A to B. It certainly has been a journey for me, so far.

Second on a good tutorial about using DPWS!

Would it be possible for you to create a sample Solution that includes the projects for both sides…

this way we can all work on the same exact code and help you get trough it, which we can eventually turn into a tutorial…

let me know if you are interested.

Jay.

Well, I was sort of doing that, but without paying attention to how others would run it (so all my namespaces aren’t really nice, and wherever IP/port/urn stuff was needed it’s all hard-coded). I suppose I could try and clean it up for general consumption. It can be, eventually, used as a basis for the tutorial.

I’ll see what I can do over the next day or so and post it up.

Cool,
thanks for taking the time and your help to kick start this tutorial.

Jay.

First, some very good news. Finally managed to get data through. My button press query service is successfully reporting the state of my Gadgeteer button.

Secondly, I have to apologize for taking so long. Last week has been very busy for me (and will be so for another 3 or so weeks), so I haven’t really had much time to play with this project. Over the next little while I will try to come up with a clean example of a Gadgeteer based DPWS service. I also need to do it to remind myself of all the pitfalls I encountered along the way, as I didn’t keep as clean a record of what I was doing the first time around, as I would have liked.

We look forward to seeing some tutorial, ideally on the wiki. We are ready to help as well.

I started reworking the example from scratch. This time, I am keeping track of what I’m doing. So far I got the device host up and running (that’s the easy part).

I posted the play-by-play on my blog.

I will write up the WCF client separately–it will be a shorter write-up, but it’s a harder task. I hope I’ll be able to do that tomorrow. Once that’s all done, I can upload the code for the example and write up an actual wiki post that doesn’t read like my stream of consciousness. :smiley:

1 Like

Excellent start! Thank you.

OData service and client would be killer. With OData (WCF Data Services) you can easily hookup Lightswitch (et al) to it as a datasource.

Excellent write up indeed…

Great. I am afraid this will be lost over time. Do you mind if we copy to wiki then add a link to our tutorial page? It is totally up to you.

Not at all Gus. Do whatever you need. I just put it up on my blog like that because it was easier for me to write it up as such while working on it. By all means, use that information however you can to fill in the documentation gaps.

–edit–
I still intend to finish off the second half, and put it all in the wiki. But if you would like to get a head start on the wiki with a standard format, that would be fantastic.

Here’s the second half of the tutorial post:

I would really appreciate it if someone could attempt to follow the instructions and verify that they can successfully communicate between the device and a client app on the computer. I will hold off uploading any code and jumping on the wiki, until I know that the example works for someone other than me.

Great! Thank you.

@ MoonDragon - I have a project this would be perfect for. I’ll definitely test your blog articles, but I have no idea when I’ll be able to make some time (at least a week out).

No sweat. This stuff won’t get lost in a week. And I would feel a lot more comfortable knowing that my amateurish tutorial works beyond my computer/head.

Let me know if you find something confusing, and/or something needs clarification.

Hi MoonDragon.
i followed your steps and created the Projects, the verdict is:
********************** it WORKS ******************** !!! ;D

i had to modify few things, nothing big…



in the buttonValue_Click i had to change:

 ButtonValue bv = client.getButtonValue(new EmptyValue());

to 

 ButtonValueType bv = client.getButtonValue(new EmptyValueType());

my generated files had teh Type at the end of ButtonValue and EmptyValue.

The Second thing i would recommend is maybe including the following paths to your blog… it would make it easy to find the concerned utilities, or at least give a step in the right direction


Client side:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\SvcConfigEditor.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\SvcUtil.exe

Host Side:


C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Tools\MFSvcUtil.exe

and one last thing you may want to change the wording of Pressing a Button to return value 1 to HOLDING DOWN the button to get value 1. at first i was pressing and releasing and expecting the button value to change but when i checked the code i realized that i should press and hold the button down…
other than that, very good write up and great work… :slight_smile:

Cheers…

Jay.