我在C#這樣的接口,東西:如何通過套接字封送.Net接口?
interface ITest
{
int Method1(int something);
}
所有方法都有基本類型(整數,字符串,枚舉)的參數。
現在我希望實現和客戶端運行在通過套接字進行通信的不同計算機上。我可以做手工是讓這樣的實現:
class Test : ITest
{
int Method1(int something)
{
m_Serializer.Serialize(something, m_Socket);
int result = (int)m_Serializer.Deserialize(m_Socket, typeof(int));
return result;
}
}
有沒有辦法將其自動化,即生成自動給定接口這樣的包裝?
我可以通過Reflection.Emit
手動生成,但這非常複雜。任何簡單的方法?
生成它如何?您是否期待套接字服務器接收一些數據並在接收數據時生成(通過Reflection.Emit)ITest的實現? –
聽起來很適合遙控。 – leppie
@Peter Ritchie生成一個將以「method name」「argument1」格式序列化的實現...服務器端將有一個實際實現的實例,並通過反射調用方法。 –