We want to create a NETMF web service that lives on a device.
We have read the MSDN Implementing Web Services on Your Devices. It explains Generating Service Model Code Using MfSvcUtil, which assumes that we already have a WSDL file.
How do we generate the WSDL file in the first place?
Create a NETMF service in C# and generate the WSDL from it.
First, install NEFMF with DPWS. We used NETMF 4.3 with DPWS from NETMF on Codeplex. This might also work with NETMF 4.4 or later from GitHub.
Second, add C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Tools
to your PATH. This is a convenient way to access the MFSvcUtil
.
Third, create a new NETMF project with a service. Here is a very simple one. You will need to reference MFWsStack.dll
because it contains the Ws.ServiceModel
namespace.
using Ws.ServiceModel;
namespace FooService
{
[ServiceContract]
public interface FooService
{
[OperationContract]
void Start();
}
}
Fourth, build the project.
Fifth, run the following (which is in PowerShell) to create the WSDL file.
> $projectRoot = "C:\FooService\";
> $svcAssembly = ".\bin\Debug\FooService.dll";
> $library = "C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Assemblies\le";
> $destinationDir = ".\temp";
> $destinationFile = "FooService.wsdl";
> cd $projectRoot;
> New-Item -type dir $destinationDir;
> mfsvcutil $svcAssembly /R:$library /D:$destinationDir /O:$destinationFile
ServiceContract = FooService
Operation Name = Start
Writing FooService Service Description to: .\temp\FooService.wsdl
Processing complete.
In the above script, library
is the directory that contains MFWsStack.dll
, which is our project's only external reference. The script creates the WSDL file in C:\FooService\temp\FooService.wsdl
. Hooray!