本文整理匯總了C#中System.ServiceModel.ChannelFactory.AddArtefact方法的典型用法代碼示例。如果您正苦於以下問題:C# ChannelFactory.AddArtefact方法的具體用法?C# ChannelFactory.AddArtefact怎麽用?C# ChannelFactory.AddArtefact使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ServiceModel.ChannelFactory
的用法示例。
在下文中一共展示了ChannelFactory.AddArtefact方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
public static void Main(string[] args)
{
bool exitServiceHost = false;
// Console.ReadKey();
// ISession sesh = NHibernate_Helper.Session;
// Execute("../../../ArtefactServiceHost/bin/Debug/ArtefactServiceHost.exe");
Thread serviceHostThread = new Thread(() =>
{
using (ServiceHost sh = ArtefactServiceHost.ArtefactServiceHost.BuildServiceHost())
{
try
{
sh.Open(); // need a brief thread.sleep before writing state string??
Console.WriteLine("Service: " + sh.Description.ServiceType.FullName + " (" +
sh.Description.Namespace + sh.Description.Name + ")"
);
foreach (ServiceEndpoint endpoint in sh.Description.Endpoints)
{
// foreach (OperationDescription od in endpoint.Contract.Operations)
// {
// DataContractSerializerOperationBehavior contractBehaviour =
// od.Behaviors.Find<DataContractSerializerOperationBehavior>();
// if (contractBehaviour == null)
// contractBehaviour = new DataContractSerializerOperationBehavior(od);
// contractBehaviour.
// }
Console.WriteLine(endpoint.ToString(true));
}
Console.WriteLine();
while (!exitServiceHost)
Thread.Sleep(255);
}
catch (Exception ex)
{
Console.Error.WriteLine("\nServiceHost Exception (State={0}):\n{1}\n", sh.State.ToString(), ex.ToString());
}
finally
{
if (sh.State != CommunicationState.Closed && sh.State != CommunicationState.Closing)
sh.Close();
}
}
});
try
{
Console.ReadKey();
// Start service host thread and pause for a few seconds to ensure it has started
serviceHostThread.Start();
Thread.Sleep(2880);
IArtefactRepository proxy = new ChannelFactory<IArtefactRepository>(
new NetTcpBinding(SecurityMode.None),
"net.tcp://localhost:3333/ArtefactRepository")
.CreateChannel();
Console.WriteLine("Client: proxy=\"{0}\"\n", proxy.ToString());
Artefact testArtefact = new Artefact();
Console.WriteLine("testArtefact: {0}", testArtefact.ToString());
testArtefact = (Artefact)proxy.AddArtefact(testArtefact);
Console.WriteLine("proxy.AddArtefact(testArtefact) returned Id={0}", testArtefact.Id == null ? "(null)" : testArtefact.Id.ToString());
Console.WriteLine();
}
catch (Exception ex)
{
Console.Error.WriteLine("\nIArtefactRepository Exception\n" + ex.ToString() + "\n"); // + (proxy == null ? "" : proxy.State.ToString()) + "):
}
finally
{
Console.WriteLine("Stopping service host thread...");
exitServiceHost = true;
if (serviceHostThread.Join(2880))
Console.WriteLine("Stopped cleanly\n");
else
Console.WriteLine("Thread.Join() unsuccessful\n");
}
}