I have application based on this tutorial
Method I use to test connection to server (in client app):
public class PBMBService : IService
{
private void btnPing_Click(object sender, EventArgs e)
{
ServiceClient service = new ServiceClient();
tbInfo.Text = service.Ping().Replace("\n", "\r\n");
service.Close();
}
//other methods
}
Service main function:
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8000/PBMB");
ServiceHost selfHost = new ServiceHost(typeof(PBMBService), baseAddress);
try
{
selfHost.AddServiceEndpoint(
typeof(IService),
new WSHttpBinding(),
"PBMBService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
Console.WriteLine("Serwis gotowy.");
Console.WriteLine("Naciśnij <ENTER> aby zamknąć serwis.");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("Nastąpił wyjątek: {0}", ce.Message);
selfHost.Abort();
}
}
}
In app.config I have:
<client>
<endpoint address="http://localhost:8000/PBMB/PBMBService" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService" contract="IService"
name="WSHttpBinding_IService">
<identity>
<userPrincipalName value="PPC\Pawel" />
</identity>
</endpoint>
</client>
I can change IP from here. But how can I change it during runtime (i.e. read address/IP from file)?
You can replace the service endpoint after you created your client class:
public class PBMBService : IService
{
private void btnPing_Click(object sender, EventArgs e)
{
ServiceClient service = new ServiceClient();
service.Endpoint.Address = new EndpointAddress("http://the.new.address/to/the/service");
tbInfo.Text = service.Ping().Replace("\n", "\r\n");
service.Close();
}
}
You can use the following channel factory:
using System.ServiceModel;
namespace PgAuthentication
{
public class ServiceClientFactory<TChannel> : ChannelFactory<TChannel> where TChannel : class
{
public TChannel Create(string url)
{
return CreateChannel(new BasicHttpBinding { Security = { Mode = BasicHttpSecurityMode.None } }, new EndpointAddress(url));
}
}
}
and you can use this with the following code:
Console.WriteLine(
new ServiceClientFactory<IAuthenticationChannel>()
.Create("http://crm.payamgostar.com/Services/IAuthentication.svc")
.AuthenticateUserNameAndPassWord("o", "123", "o", "123").Success);
Related
I'm trying to unittest a WCF app.
Here what I've tried:
public class Service1 : IService1
{
public string GetData(int value)
{
string val = ConfigurationManager.AppSettings["mykey"].ToString();
return string.Format("You entered: {0}. mykey={1}", value, val);
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
ServiceHost serviceHost = null;
try
{
string url = "http://localhost:56666/Serivce1";
var baseAddress = new Uri(url);
serviceHost = new ServiceHost(typeof(Service1), baseAddress);
Binding binding = new WSHttpBinding(SecurityMode.None);
serviceHost.AddServiceEndpoint(typeof(IService1), binding, "Service1");
var smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(smb);
serviceHost.Open(); // if this fails, you have to run Visual Studio as admin
BasicHttpBinding myBinding = new BasicHttpBinding();
ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(myBinding);
EndpointAddress myEndpoint = new EndpointAddress(url);
IService1 wcfClient = myChannelFactory.CreateChannel(myEndpoint);
string s = wcfClient.GetData(39);
serviceHost.Close();
}
finally
{
if (serviceHost != null)
{
((IDisposable)serviceHost).Dispose();
}
}
}
}
}
When I call wcfClient.GetData(39);
I get this error:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:56666/Serivce1 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
Any ideas why I'm getting this error and how to make it work?
I got it working but making the bindings consistent and fixing the issue related to the configuration of the WCF not getting loaded with a not-so-nice workaround:
public class Service1 : IService1
{
public string GetData(int value)
{
string val = "Nothing";
if(ConfigurationManager.AppSettings != null && ConfigurationManager.AppSettings["mykey"] != null) // when normally run
{
val = ConfigurationManager.AppSettings["mykey"].ToString();
}
else // when run via unittest:
{
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "web.config";
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
ConfigurationManager.RefreshSection("appSettings"); // this does not work, so I I wrote the loop:
foreach (KeyValueConfigurationElement kv in configuration.AppSettings.Settings)
{
ConfigurationManager.AppSettings[kv.Key] = kv.Value;
}
if (ConfigurationManager.AppSettings["mykey"] != null)
{
val = ConfigurationManager.AppSettings["mykey"].ToString();
}
}
return string.Format("You entered: {0}. mykey={1}", value, val);
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
ServiceHost serviceHost = null;
try
{
string url = "http://localhost:56669";
var baseAddress = new Uri(url);
serviceHost = new ServiceHost(typeof(Service1), baseAddress);
BasicHttpBinding binding = new BasicHttpBinding();
serviceHost.AddServiceEndpoint(typeof(IService1), binding, "");
var smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(smb);
// enabling server side exception details to help debug:
var behavior = serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
behavior.IncludeExceptionDetailInFaults = true;
serviceHost.Open(); // if this fails, you have to run Visual Studio as admin
ChannelFactory<IService1> myChannelFactory = new ChannelFactory<IService1>(binding);
EndpointAddress myEndpoint = new EndpointAddress(url);
IService1 wcfClient = myChannelFactory.CreateChannel(myEndpoint);
string result = wcfClient.GetData(39);
Assert.AreEqual(string.Format("You entered: {0}. mykey=myval", 39), result);
serviceHost.Close();
}
finally
{
if (serviceHost != null)
{
((IDisposable)serviceHost).Dispose();
}
}
}
}
Any suggestions to improve the configuration loading would be welcome.
I have created a web service that exposes web interface.
the service run in console mode and i see the web interface
public ServiceHost serviceHost = null; public ServiceHost serviceHost = null;;
private readonly TestService s;
public Service()
{
InitializeComponent();
s = new TestService();
}
protected override void OnStart(string[] args)
{
Logger.Info("Start event");
if (serviceHost != null)
{
serviceHost.Close();
}
// Create a ServiceHost for the CalculatorService type and
// provide the base address.
string baseAddress = "http://localhost:8000/Service";
serviceHost = new ServiceHost(typeof(Service1), new System.Uri(baseAddress));
serviceHost.AddServiceEndpoint(typeof(WindowsServiceTemplate.IService1),
new BasicHttpBinding(), baseAddress);
// Check to see if the service host already has a ServiceMetadataBehavior
ServiceMetadataBehavior smb = serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
// If not, add one
if (smb == null)
smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
serviceHost.Description.Behaviors.Add(smb);
// Add MEX endpoint
serviceHost.AddServiceEndpoint(
ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexHttpBinding(),
"mex"
);
// Open the ServiceHostBase to create listeners and start
// listening for messages.
serviceHost.Open();
s.Start();
}
protected override void OnStop()
{
Logger.Info("Stop event");
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
s.Stop();
}
protected override void OnShutdown()
{
Logger.Info("Windows is going shutdown");
Stop();
}
public void Start()
{
OnStart(null);
}
}
}
and app.config file :
<system.serviceModel>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="WindowsServiceTemplate.IService1" behaviorConfiguration="MyServiceTypeBehaviors" >
<!-- Add the following endpoint. -->
<!-- Note: your service must have an http base address to add this endpoint. -->
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mexHttpBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
the configuration file inside app.config (console application project)
i am able to access
http://localhost:8000/Service
but when i try to call the test method
http://localhost:8000/Service/test
i get 404 error.
what am i missing?
Use Webhttpbinding to create the service and webservicehost to host service. I have made a demo, wish it is useful to you.
public partial class Service1 : ServiceBase
{
ServiceHost sh = new ServiceHost(typeof(MyService), new Uri("http://localhost:5900"));
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (sh.State==CommunicationState.Opened)
{
Log("Service open Fail");
}
else
{
WebHttpBinding webHttpBinding = new WebHttpBinding();
ServiceEndpoint se = sh.AddServiceEndpoint(typeof(IService), webHttpBinding, "");
se.EndpointBehaviors.Add(new WebHttpBehavior());
sh.Open();
Log("Service is ready....");
}
}
protected override void OnStop()
{
if (sh.State==CommunicationState.Opened)
{
sh.Close();
Log("Service closed successfully");
}
}
private void Log(string text)
{
using (StreamWriter sw=new StreamWriter(#"D:\log.txt",true))
{
sw.WriteLine($"{text}----Time:{DateTime.Now.ToShortTimeString()}");
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet]
string SayHello();
}
public class MyService : IService
{
public string SayHello()
{
return "Hello Stranger";
}
}
}
Install.
Result.
Here is an official document.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
Feel free to let me know if there is anything I can help with.
I'm new to wcf and learning how to build one, with callbacks. I got an example from the following link:
http://architects.dzone.com/articles/logging-messages-windows-0
I tried implementing the wcf but when i run this in as a test by pressing f5, the test client says:
The service contract is not supported in the wcf client.
Service:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.PerCall)]
public class RatsService : IRatsService
{
public static List<IRatsServiceCallback> callBackList = new List<IRatsServiceCallback>();
public RatsService()
{
}
public void Login()
{
IRatsServiceCallback callback = OperationContext.Current.GetCallbackChannel<IRatsServiceCallback>();
if (!callBackList.Contains(callback))
{
callBackList.Add(callback);
}
}
public void Logout()
{
IRatsServiceCallback callback = OperationContext.Current.GetCallbackChannel<IRatsServiceCallback>();
if (callBackList.Contains(callback))
{
callBackList.Remove(callback);
}
callback.NotifyClient("You are Logged out");
}
public void LogMessages(string Message)
{
foreach (IRatsServiceCallback callback in callBackList)
callback.NotifyClient(Message);
}
Service Interface
[ServiceContract(Name = "IRatsService", SessionMode = SessionMode.Allowed, CallbackContract = typeof(IRatsServiceCallback))]
public interface IRatsService
{
[OperationContract]
void Login();
[OperationContract]
void Logout();
[OperationContract]
void LogMessages(string message);
// TODO: Add your service operations here
}
public interface IRatsServiceCallback
{
[OperationContract]
void NotifyClient(String Message);
}
App.config:
<system.serviceModel>
<services>
<service name="RatsWcf.RatsService">
<endpoint address="" binding="wsDualHttpBinding" contract="RatsWcf.IRatsService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/RatsWcf/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
Just wondering what could be wrong here.
There's nothing wrong. The WCF Test Client is a tool which can be used to test many types of WCF services, but not all of them - duplex contracts being one category which is not supported. You'll need to create some sort of client app to test that. In your client app you'll need to write a class which implements the callback interface, so that it can receive the messages initiated by the service.
For example, this is a very simple duplex client / service which uses WCF duplex:
public class DuplexTemplate
{
[ServiceContract(CallbackContract = typeof(ICallback))]
public interface ITest
{
[OperationContract]
string Hello(string text);
}
[ServiceContract(Name = "IReallyWantCallback")]
public interface ICallback
{
[OperationContract(IsOneWay = true)]
void OnHello(string text);
}
public class Service : ITest
{
public string Hello(string text)
{
ICallback callback = OperationContext.Current.GetCallbackChannel<ICallback>();
ThreadPool.QueueUserWorkItem(delegate
{
callback.OnHello(text);
});
return text;
}
}
class MyCallback : ICallback
{
AutoResetEvent evt;
public MyCallback(AutoResetEvent evt)
{
this.evt = evt;
}
public void OnHello(string text)
{
Console.WriteLine("[callback] OnHello({0})", text);
evt.Set();
}
}
public static void Test()
{
string baseAddress = "net.tcp://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
host.AddServiceEndpoint(typeof(ITest), new NetTcpBinding(SecurityMode.None), "");
host.Open();
Console.WriteLine("Host opened");
AutoResetEvent evt = new AutoResetEvent(false);
MyCallback callback = new MyCallback(evt);
DuplexChannelFactory<ITest> factory = new DuplexChannelFactory<ITest>(
new InstanceContext(callback),
new NetTcpBinding(SecurityMode.None),
new EndpointAddress(baseAddress));
ITest proxy = factory.CreateChannel();
Console.WriteLine(proxy.Hello("foo bar"));
evt.WaitOne();
((IClientChannel)proxy).Close();
factory.Close();
Console.Write("Press ENTER to close the host");
Console.ReadLine();
host.Close();
}
}
Have run into a slight problem regarding Client Connections that need to be passed between threads.
1.) We have a service class
public class Service : ServiceBase
{
public ServiceHost serviceHost = null;
public CMLiteService()
{
ServiceName = "MyService";
}
public static void Main()
{
ServiceBase.Run(new Service());
}
protected override void OnStart(string[] args)
{
try
{
if (serviceHost != null)
{
serviceHost.Close();
}
Uri baseAddress = new Uri("net.pipe://localhost/Service");
// Step 2 Create a ServiceHost instance
serviceHost = new ServiceHost(typeof(Service), baseAddress);
// Step 3 Add a service endpoint.
serviceHost.AddServiceEndpoint(typeof(IService), new NetNamedPipeBinding(), "Service");
serviceHost.Open();
}
catch(Exception e)
{
}
}
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
}
2.) We have an interface
[ServiceContract]
public interface IService
{
[OperationContract]
string InitalizeDataStore(string uri1, string uri2);
[OperationContract]
string CheckHealth();
[OperationContract]
string CreateObject(string parameters);
}
3.) We have a method that Initializes Our data storage
ObjectOperations objectOperations;
public InitalizeDataStore (string uri1, string uri2)
{
Admin admin = new Admin(uri1, uri2);
objectOperations = new ObjectOperations(admin.client1, admin.client2);
}
4.) Here is the admin class that does the actual connecting to the database, both there clients are thread safe and support multithreading
StorageClient1 client1
StorageClient2 client2
string URI1;
string URI2;
public AdminServices(string uri1, string uri2)
{
URI1 = uri1;
URI2 = uri2;
InitializeClient1();
InitializeClient2();
}
public StorageClient1 InitializeClient1()
{
try
{
client1 = new Client(new Uri(URI1));
client1.Connect();
return client1;
}
catch (Exception e)
{
throw e;
}
}
public Client2 InitializeClient2()
{
try
{
client2 = new Client(new Uri(URI2));
client2.Connect();
return client2;
}
catch (Exception e)
{
throw e;
}
}
5.) When we start the service and run the initialization method it connects and works. But when we start another process the client connections are null? If we run the code top down in one console app it works but we are in need of running initialization once and then the client connection must be set for future processes.
So Process 1:
IService pipeProxy = pipeFactory.CreateChannel();
pipeProxy.InitalizeDataStore(); //Returns "Connected"
Process 2:
IService pipeProxy = pipeFactory.CreateChannel();
pipeProxy.CheckHealth(); //returns null
How do we insure that the Client Connection details are also made availible in another process. I am very new too this so Im not too clued up on multithreading.
I believe what you are trying to accomplish is served by the WCF Singleton instance mode:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
Attribute your implementing class with the above, and all clients will share an instance.
I am having a weird problem. If the WCF host is hosted in the original AppDomain, the code takes 1.25s to execute. However if I put it in a new AppDomain, despite the fact that I still use net.pipe or net.tcp to talk to it, the process takes 4.7s to run. Here is the code with app.config in the commented out block on the bottom.
namespace ConsoleApplication2
{
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Reflection;
using System.ServiceModel;
using System.Threading.Tasks;
using Client;
internal class Program
{
#region Methods
private static void Main(string[] args)
{
var p = new Program();
p.Execute();
}
#endregion
public void Execute()
{
var hosts = Enumerable.Range(0, 1).Select(CreateNewHost).ToArray();
var r = new Random();
var cb = new ConcurrentDictionary<int, string>();
Action a = () =>
{
try
{
Parallel.For(
0,
10000,
i =>
{
//string ep = String.Format("net.pipe://localhost/iService{0}", hosts[r.Next(0, hosts.Length)]);
string ep = String.Format("net.tcp://localhost:{0}/iService", hosts[r.Next(0, hosts.Length)]);
string s=null;
//using (var cli = new ServiceClassClient("NetNamedPipeBinding_IServiceClass", ep))
using (var cli = new ServiceClassClient("NetTcpBinding_IServiceClass", ep))
{
s = cli.Ping();
}
if (!String.IsNullOrEmpty(s))
{
cb[i] = s;
}
});
}
catch (AggregateException aggregateException)
{
Console.WriteLine(aggregateException);
}
};
Console.WriteLine("\n\nIt took {0:G}", a.TimeThis());
Console.ReadKey();
}
static int CreateNewHost(int s)
{
//uncomment for in-process host
//var h1 = new Host();
//return h1.Port;
var appDomain = AppDomain.CreateDomain(
"A" + s,
null,
new AppDomainSetup
{
LoaderOptimization = LoaderOptimization.MultiDomain,
DisallowBindingRedirects = true
});
var assemblyName = Assembly.GetAssembly(typeof(Host)).FullName;
var h = appDomain.CreateInstanceAndUnwrap(assemblyName, typeof(Host).FullName) as Host;
return h.Port;
}
}
//comment out MarshalByRefObject for in-process host
public class Host:MarshalByRefObject
{
#region Fields
private readonly ServiceHost host;
private readonly int port;
#endregion
#region Constructors and Destructors
public Host()
{
this.port = this.GetFreePort();
var ub = new UriBuilder { Host = "localhost", Port = this.port, Scheme = "net.tcp" };
var up = new UriBuilder { Host = "localhost", Scheme = "net.pipe", Path = "iService" + this.port };
this.host = new ServiceHost(typeof(ServiceClass), ub.Uri);
var netNamedPipeBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
this.host.AddServiceEndpoint(typeof(IServiceClass), netNamedPipeBinding, up.Uri);
var un = new UriBuilder { Host = "localhost", Port = this.port, Scheme = "net.tcp", Path = "iService" };
var netTcpBinding = new NetTcpBinding(SecurityMode.None);
this.host.AddServiceEndpoint(typeof(IServiceClass), netTcpBinding, un.Uri);
//#if DEBUG
//var us = new UriBuilder { Host = "localhost", Port = this.port, Scheme = "http", Path = "iServiceMeta" };
//var smb = new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = us.Uri };
//this.host.Description.Behaviors.Add(smb);
//#endif
this.host.Open();
Console.WriteLine("Listening at {0}", this.host.BaseAddresses[0].AbsoluteUri);
}
#endregion
#region Public Properties
public int Port
{
get
{
return this.port;
}
}
public ServiceHost ServiceHost
{
get
{
return this.host;
}
}
#endregion
#region Methods
private int GetFreePort()
{
TcpConnectionInformation[] connections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections();
IPEndPoint[] listeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners();
var udps = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();
var r = new Random();
int port;
do
{
port = r.Next(1025, 65534);
}
while (listeners.Any(a => a.Port == port) || connections.Any(a => a.LocalEndPoint.Port == port) || udps.Any(a=>a.Port==port));
return port;
}
#endregion
}
[ServiceContract]
internal interface IServiceClass
{
#region Public Methods and Operators
[OperationContract]
string Ping();
#endregion
}
internal class ServiceClass : IServiceClass
{
#region Public Methods and Operators
public string Ping()
{
return ((new Random()).NextDouble() * (new Random()).NextDouble()).ToString("F11");
}
#endregion
}
public static class Extensions
{
#region Public Methods and Operators
public static TimeSpan TimeThis(this Action action)
{
var sw = new Stopwatch();
sw.Start();
action.Invoke();
sw.Stop();
return sw.Elapsed;
}
#endregion
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18033
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Client
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "IServiceClass")]
public interface IServiceClass
{
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IServiceClass/Ping", ReplyAction = "http://tempuri.org/IServiceClass/PingResponse")]
string Ping();
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IServiceClassChannel : IServiceClass, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class ServiceClassClient : System.ServiceModel.ClientBase<IServiceClass>, IServiceClass
{
public ServiceClassClient()
{
}
public ServiceClassClient(string endpointConfigurationName)
: base(endpointConfigurationName)
{
}
public ServiceClassClient(string endpointConfigurationName, string remoteAddress)
: base(endpointConfigurationName, remoteAddress)
{
}
public ServiceClassClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress)
: base(endpointConfigurationName, remoteAddress)
{
}
public ServiceClassClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress)
: base(binding, remoteAddress)
{
}
public string Ping()
{
return base.Channel.Ping();
}
}
}
/*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IServiceClass">
<security mode="None" />
</binding>
</netNamedPipeBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IServiceClass">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="" binding="netNamedPipeBinding"
bindingConfiguration="NetNamedPipeBinding_IServiceClass" contract="IServiceClass"
name="NetNamedPipeBinding_IServiceClass" />
<endpoint address="" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IServiceClass" contract="IServiceClass"
name="NetTcpBinding_IServiceClass" />
</client>
</system.serviceModel>
</configuration>
*/
You might get improved performance by decorating your Main method with LoaderOptimization attribute. This shares common resources across app domains.
[LoaderOptimization(LoaderOptimization.MultiDomain)]
See this answer for more details.