I am trying to host the WCF net.pipe service in a windows service. I define a service in code in a Windows Service function OnStart(). I also create a client in the same way - in code.
I saw this question, but it always seems that it focuses only on situations where NetNamedPipe is defined in the app / web.config file.
When I try to call a service, I get an error message:
System.ServiceModel.ProtocolException: The requested upgrade is not supported by 'net.pipe://localhost/manager'. This could be due to mismatched bindings (for example security enabled on the client and not on the server).
Server stack trace:
at System.ServiceModel.Channels.ConnectionUpgradeHelper.DecodeFramingFault(ClientFramingDecoder decoder, IConnection connection, Uri via, String contentType, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MyClientApp.IManager.HelloWorld()
Here is my code:
[ServiceContract]
public interface IManager
{
[OperationContract]
string HelloWorld();
}
public class Manager : IManager
{
public string HelloWorld()
{
return "Hello to you too!";
}
}
public partial class MyWindowsService : ServiceBase
{
public MyWindowsService()
{
InitializeComponent();
}
private ServiceHost m_serviceHost;
protected override void OnStart(string[] args)
{
try
{
m_serviceHost = new ServiceHost(typeof(Manager), new Uri("net.pipe://localhost"));
NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
m_serviceHost.AddServiceEndpoint(typeof(IManager), binding, "manager");
m_serviceHost.Open();
}
catch (Exception ex)
{
EventLog("MyWindowsService", ex.ToString(), EventLogEntryType.Error);
}
}
}
public class ManagerProxy : ClientBase<IManager>
{
public ManagerProxy()
: base(new ServiceEndpoint(ContractDescription.GetContract(typeof(IManager)),
new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/manager"))) { }
public string InvokeHellowWorld()
{
return Channel.HelloWorld();
}
}
The interface is in the ClassLibrary project and is shared between the host application (Windows service) and the client application that is trying to call the service.
The service class and OnStart function are in the Windows service project.
The service proxy is located in the client project (which, of course, starts from the same computer as the Windows service).
, , -, State == CommunicationState.Faulted. / new ManagerProxy(). ManagerProxy Created. HelloWorld Exception.
, , Faulted, .