私はWCFの初心者です。デバイスドライバネットワークにアクセスできるようにしようとしています。私が今持っているコード、簡略化:
A.cs
public class A {
public int source;
}
Driver.cs
public class Driver {
// some fields here
A a;
// singleton class
private Driver() {
a = null;
// some more code
}
// static methods
public static Driver OpenDevice(int n) {
Driver d = null;
// some code
i = GetBoardNumber();
// some native code to actually open driver ONLY IF it wasn't already opened!
d = new Driver();
return d;
}
public static int GetDeviceNumber() {
// some native code get device number
return someInt;
}
// some non static methods which use native code
// example:
public int ResetDevice(){
// some code
// call native i_ResetDevice() method
return code;
}
}
DllImport.cs
public class DllImport {
// some code to import method definitions from dll
// example:
[DllImport("MyDeviceDriverProvidedForWindows.dll")]
public static extern int i_ResetDevice();
// some more code
}
このドライバーは私にとって非常にうまく機能します。デバイスを制御する例では、このドライバーへの参照を追加し、ドライバーのメソッドを使用してデバイスを制御します。
MyService d = Driver.OpenDevice(0);
d.ControlDevice();
私の仕事は、このドライバーをリモートでアクセスできるようにすることであり、WCFを使用してそれを行うことを選択しました。
すでに実装しているので、インターフェイスを抽出し、OperationContractsと適切な場所を配置することで有効なWCFサービスコントラクトに変換しました。この抽出されたインターフェイスには、静的であるため、OpenDeviceメソッドとGetDeviceNumberメソッドがありませんでした。
私が抱えている問題は次のとおりです。
1)WSDLファイルを開くと、クライアントで次のようなコードを使用するように指示されます。
MyServiceClient client = new MyServiceClient();
// access client operations
// close client
client.Close();
これは何ですかMyServiceRefernce.MyServiceClient
(MyServiceReference
クライアントに追加したサービス参照の名前です)?サーバー上のMyServiceクラスのプライベートコンストラクターを呼び出すのはなぜですか?
2)クライアントでこのようなことをするにはどうすればよいですか?
MyServiceReference.Driver d = MyServiceRefernce.Driver.OpenDevice(0);
私は自分の状況について読んだことInstanceContextMode
がありますが、それをどのように使用するかはよくわかりません。
私が何を求めているのかを正確に理解するのは難しいことは理解していますが、私も説明するのは本当に難しいです!WCFをよく知っている人がいたらいいのにと思います。
私が使用している実際のドライバーソースは、このファイルのアセンブリフォルダーにあります。