I declare my interface:
|
| [ServiceContract(Namespace = "DocumtrCommunication")] |
|
| public
interface
IDocumtrContract |
|
|
|
| List<string> ExecuteQueryReturnIDs(string optionalContextId, string query); |
|
|
| string IdAndAttributeToString(string id, string attribute); |
|
|
| Stream IdAndAttributeToImage(string id, string attribute); |
|
|
And I implement the interface in the server:
|
| namespace TestSysForDocumtr |
|
|
| public
class
Server : IDocumtrContract |
|
|
| public
static
Uri baseAddress = new
Uri("net.pipe://localhost/MyPipe3"); |
|
|
| #region IDocumtrContract Members |
|
|
| List<string> IDocumtrContract.ExecuteQueryReturnIDs(string optionalContextId, string query) |
|
|
| return
Form1.ExecuteOCL(optionalContextId,query); |
|
|
| string
IDocumtrContract.IdAndAttributeToString(string id, string attribute) |
|
|
| return
Form1.IdToString(id, attribute); |
|
|
|
| Stream
IDocumtrContract.IdAndAttributeToImage(string id, string attribute) |
|
|
|
|
|
|
|
|
|
I start the server (I commented out the meta data exposure part since I will write my client myself)
|
| ServiceHost selfHost = new
ServiceHost(typeof(Server), Server.baseAddress); |
|
| selfHost.AddServiceEndpoint( |
|
| typeof(IDocumtrContract), |
|
| new
NetNamedPipeBinding(), |
|
|
|
| //ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); |
|
| //smb.HttpGetEnabled = true; |
|
| //smb.HttpGetUrl = new Uri("http://localhost:8001/DocumtrContract"); |
|
| //selfHost.Description.Behaviors.Add(smb); |
|
|
|
|
And now the client:
|
| public
partial
class
WCFClientImpl : System.ServiceModel.ClientBase<DocumtrCommunication.IDocumtrContract>, DocumtrCommunication.IDocumtrContract |
|
|
|
|
| public WCFClientImpl(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : |
|
| base(binding, remoteAddress) |
|
|
|
|
|
| #region IDocumtrContract Members |
|
|
|
| public
List<string> ExecuteQueryReturnIDs(string optionalContextId,string query) |
|
|
| return
base.Channel.ExecuteQueryReturnIDs(optionalContextId,query); |
|
|
| public
string IdAndAttributeToString(string id, string attribute) |
|
|
| return
base.Channel.IdAndAttributeToString(id, attribute); |
|
|
| public
Stream IdAndAttributeToImage(string id, string attribute) |
|
|
| return
base.Channel.IdAndAttributeToImage(id,attribute); |
|
|
|
|
|
|
|
And this is how I call the server from the client:
|
| EndpointAddress endpointAddress = new
EndpointAddress("net.pipe://localhost/MyPipe3"); |
|
| NetNamedPipeBinding binding = new
NetNamedPipeBinding(); |
|
| WCFClientImpl x = new
WCFClientImpl(binding,endpointAddress); |
|
|
| List<string> ss=x.ExecuteQueryReturnIDs("","Class1.allinstances"); |
|
Done.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home