key Words:DPWS、嵌入式裝置、WebService、Http、嗅探、Micro Framework。。
為了實現一個嵌入式裝置和一個宿主在 IIS Server 上面的 WebService 交互,使用了 MF3.0 裡面的 DPWS 方法。不過這個東西實在是 Hard to use。今天就記錄下使用的過程中的第一步,首先分析一個 Client 和一個 Webservice 是如何交互的,發送的資料流的格式,然後在 Device 裡面封裝一下 Soap 頭用 HttpClient 發送出去。
這裡用到了 WireShark 來分析網路交互的資料包。
首先定義一個運行在 IIS 上面的簡單的 WebService:
namespace Cashfree.Vending.Web.WebService
{
[WebService(Namespace = "https://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class IISWS : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello Robin";
}
[WebMethod]
public int add(int a, int b)
{
return a + b;
}
}
}
然後定義一個 Client 來存取這個 Webservice:
namespace Cashfree.Vending.IISWSInvoke
{
class Program
{
static void Main(string[] args)
{
ISWSSoapClient isClient = new ISWSSoapClient();
Console.WriteLine(isClient.add(2, 3));
}
}
}