Update
The service is running and has a pid in Task Manager but when I run netstat -ano | find pid# nothing is returned - the port is not listening.
Also if I run netstat -ap tcp the port is not listed.
I really don't know how to fix this. In summary so you don't have to read my previous post:
My WCF Service works perfectly under localhost (ie service and client on same server)
When I publish the Service to a production server, the service installs fine but the 8523 port does not listen
There are several similar posts that I have reviewed but none work for me
This is my first WCF project that I have attempted so I have exhausted my knowledge and I can't find any more examples on the Internet to try
At this point I will be very grateful for any pointers
environment
development: Windows 7
Visual Studio: 2015
production server: Windows Server 2008 R2 Datacenter
IIS version 7.5.7600.16385
Introduction
I have researched this issue for a few days now and although I have found a number of similar questions on Stack Overflow, none of those questions solve my problem; therefore I don't think this is a duplicate and it will be specifically helpful if someone is trying to follow the referenced Microsoft tutorial as I have done
Problem details
I have followed this Microsoft article "How to: Host WCF in a Windows Service Using TCP" at https://msdn.microsoft.com/en-us/library/ff649818.aspx.
After creating the solution, it runs perfectly on my development machine within the Visual Studio localhost environment. The tutorial suggests that you create a Test Client to access the WCF solution and that Test client works successfully
When I publish the WCF Service and the Windows Service in the production machine (Windows Server 2008) it again installs without error. Here are the steps that I follow:
IIS Setup
add net.tcp to the enabled protocols
activate 'Windows Communication Foundation Non-HTTP Activation'
Changed bindings for net.tcp to 8532
Ensure 'Net.Tcp Listener Adapter' is running
Open 8532 port in firewall
Browse to the bin directory of the project where WindowsService1.exe is located and run the exe as administrator
Open command Prompt as administrator and run Installutil WindowsService1.exe
Differences between Localhost (development environment in Visual Studio) and Production environment
The only changes between the localhost WCF system and production system is I changed the baseAddress in app.conf from
"net.tcp://localhost:8523/CustomWCFService"
to
"net.tcp://10.2.1.1:8523/CustomWCFService"
Here is the deployed app.conf
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="MyCustomServiceLib.CustomServiceLib">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="MyCustomServiceLib.ICustomServiceLib">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://10.2.1.1:8523/CustomWCF" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Adding Service Reference
When I try to add the service reference in my application that will use the WCF service. I get this error:
There was an error downloading metadata from the address. Please
verify that you have entered a valid address
When I click on "Details" I see this:
The URI prefix is not recognized. Metadata contains a reference that
cannot be resolved: 'net.tcp://10.2.1.1:8523/CustomWCF'. Could not
connect to net.tcp://10.2.1.1:8523/CustomWCF. The connection attempt
lasted for a time span of 00:00:01.0312368. TCP error code 10061: No
connection could be made because the target machine actively refused
it 10.2.1.1:8523. No connection could be made because the target
machine actively refused it 10.2.1.1:8523 If the service is defined in
the current solution, try building the solution and adding the service
reference again.
What I have tried
A lot of the other WCF questions asked on forums seem to be in regards to getting the service working in localhost which does not apply to me because the solution I've created works perfectly in the development environment.
Some of the answers suggest enabling tcp port sharing in the project but when I try and add this code in my solution I get an error saying "not allowed".
Other questions suggest that the url must be registered on the production server but that has no effect.
After trying all the forum suggestions that I can find and trying to correct everything that I think is wrong, I've still have no luck.
Any suggestions or pointers will be greatly appreciated
I have not gotten WCF to work well with the configuration file in the past. I have always created the bindings in code.
This gist does work.
The important parts are NetTcpBinding
netTcpBinding = new NetTcpBinding
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferPoolSize = int.MaxValue,
Security = new NetTcpSecurity
{
Mode = SecurityMode.None,
Transport = new TcpTransportSecurity()
}
};
Also I would not specify an IP but rather let WCF bind it to every IP Address on the machine.
serviceHost.AddServiceEndpoint(typeof(ITestService), netTcpBinding, string.Format("{1}://0.0.0.0:{0}/", port, "net.tcp"));
This does not prevent you putting in a specific IP, I just typically do not.
If you want to run it in IIS you have to do a little bit more work. IIS doesn't really want you to host a WCF server that is not bound in by http.
You have to do a little extra work after creating the ServiceHost
var serviceBehavior = serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (serviceBehavior == null) return;
serviceBehavior.HttpGetEnabled = false;
serviceBehavior.HttpsGetEnabled = false;
I've added this post to detail the results of adding David Basarab suggested changes to my WCF Service Library project. Again many thanks for David's post, but unfortunately I couldn't get it to work. In fact it didn't even run under localhost in Visual Studio. David mentioned that it worked for him so I probably make a mistake somewhere. Hopefully the details that I provide here will either generate some additional pointers to what I did wrong or help someone else that tries David's approach. I tried to keep the Visual Studio default values when creating the Solution except for David's changes.
Service Reference Error
Here's the error that I received when I tried to add the Service Reference in my Test Client on the same machine as both the Windows Service and the actual WCF Service Library:
The URI prefix is not recognized. Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8523/Service1'. Could not connect to net.tcp://localhost:8523/Service1. The connection attempt lasted for a time span of 00:00:02.0028015. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8523. No connection could be made because the target machine actively refused it 127.0.0.1:8523 If the service is defined in the current solution, try building the solution and adding the service reference again.
WCF Library code
IService1.cs unit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace CustomServiceLibrary
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
// You can add XSD files into the project. After building the project, you can directly use the data types defined there, with the namespace "CustomServiceLibrary.ContractType".
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
Service1.cs code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace CustomServiceLibrary
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
Server.cs class code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace CustomServiceLibrary
{
class Server
{
private readonly ushort port;
private readonly Service1 Service1;
private NetTcpBinding netTcpBinding;
private ServiceHost serviceHost;
public Server(ushort port)
{
this.port = port;
Service1 = new Service1();
}
public void Start()
{
try
{
CreateServiceHost();
CreateBinding();
AddEndpoint();
serviceHost.Open();
Console.WriteLine("Service has been opended");
ConfigureHTTP();
}
catch (Exception ex)
{
Console.WriteLine($"ERROR := {ex.Message}");
Console.WriteLine($"StackTrace := {ex.StackTrace}");
}
}
private void AddEndpoint()
{
serviceHost.AddServiceEndpoint(typeof(IService1), netTcpBinding, string.Format("{1}://0.0.0.0:{0}/", port, "net.tcp"));
}
private void ConfigureHTTP()
{
var serviceBehavior = serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (serviceBehavior == null) return;
serviceBehavior.HttpGetEnabled = false;
serviceBehavior.HttpsGetEnabled = false;
}
private void CreateBinding()
{
netTcpBinding = new NetTcpBinding
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferPoolSize = int.MaxValue,
Security = new NetTcpSecurity
{
Mode = SecurityMode.None,
Transport = new TcpTransportSecurity()
}
};
}
private void CreateServiceHost()
{
serviceHost = new ServiceHost(Service1);
}
}
}
Summary
Other than David's changes that I added to the project, everything else that I did was the same as what I did for the previous deployment using App.conf configuration. I just followed the directions in Microsoft article "How to: Host WCF in a Windows Service Using TCP" at https://msdn.microsoft.com/en-us/library/ff649818.aspx
Related
Consider this scenario:
A WCF service is up and running.
The service needs to call itself every once in a while.
What I did now is add a service reference to the same service and added an extra endpoint + client in the service configuration file. Working over net.tcp.
It works fine, but I read somewhere that you can use "in process" hosting to connect to a service without using a proxy. This way you can get rid of the configuration and have much cleaner code.
So instead of this with the accompying configuration settings:
DeliveryOwnClient.DeliveryClient deliveryObject = new DeliveryOwnClient.DeliveryClient("netTcpDeliveryService");
I want to use this without any configuration:
IDelivery deliveryObject = InProcessFactory.CreateInstance<DeliveryService.Delivery, IDelivery>();
But this throws an exception that "The ChannelDispatcher at http://localhost:8003/DeliveryService with contract "IMetadataExchange" can't open the IChannelListener. A registration already exists for Uri net.tcp://localhost:9003/DeliveryService"
The implementation for CreateInstance looks like this:
ServiceHost host = new ServiceHost(typeof(S));
string address = "net.pipe://" + Environment.MachineName + "/" + Guid.NewGuid();
host.AddServiceEndpoint(typeof(I), Binding, address);
host.Open();
So I'm adding a net.pipe baseaddress and it fails because there is something running over net.tcp already.
** edit **
Figured out at least why this is happening.
The service is configured in the app.config with two baseaddresses
<service name="DeliveryService.Delivery">
<endpoint binding="netTcpBinding" contract="DeliveryService.IDelivery"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8003/DeliveryService" />
<add baseAddress="net.tcp://localhost:9003/DeliveryService" />
</baseAddresses>
</host>
</service>
When the host is constructed
ServiceHost host = new ServiceHost(typeof(S));
It find that section in the config file and automatically adds net.tcp and http base addresses.
I add net.pipe, but that doesnt matter. When the service is opened it finds that net.tcp is already running so it wont continue.
So I guess my question is changed into: Is it possible to construct a ServiceHost without having it read app.config?
Jay managed to figure it out! ServiceHost derives from ServiceHostBase and that class has a virtual function named ApplyConfiguration. So I made a class which derives from ServiceHost and overrides ApplyConfiguration...and leave it empty.
class ServiceHostNoConfig<S> : ServiceHost where S : class
{
public ServiceHostNoConfig(string address)
{
UriSchemeKeyedCollection c = new UriSchemeKeyedCollection(new Uri(address));
InitializeDescription(typeof(S), c);
}
public new void InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
{
base.InitializeDescription(serviceType, baseAddresses);
}
protected override void ApplyConfiguration()
{
}
}
Use it like this:
ServiceHost host = new ServiceHostNoConfig<S>(address);
host.AddServiceEndpoint(typeof(I), Binding, address);
Fairly new to SOAP however not new to C# or PHP. I have created a basic SOAP service at http://basic.tip2tail.co.uk/?wsdl. This should expose a method submitSoap which takes a string parameter and returns an integer.
I have tested this SOAP service by connecting a simple client I have written in another language and confirmed it works as expected.
However, I cannot get my head round this in C#. I have added a Service Reference pointing at my WSDL. It shows as 2 services. The method shows as exposed under BasicSOAP_PortType.
I have then added using SOAPTest.BasicSOAP; to my C# program. However I cannot work out how to then code a call to this method. I thoughts it would be similar to (in a button click event):
BasicSOAP_PortType oSoap = new BasicSOAP_PortType();
int iReturn = oSoap.submitSoap("this is the string sent");
However this does not work and generates the following exception:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll
Additional information: Could not find default endpoint element that references contract 'BasicSOAP.BasicSOAP_PortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Any help appreciated!
Mark
I got it to work. After adding the service ref, my code looks like this:
using (var client = new basicsoap_ref.BasicSOAP_PortTypeClient())
{
try
{
int result = 0;
string resultString = client.submitSoap("<root><test>Will</test></root>");
int.TryParse(resultString, out result);
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
Console.Write("Done");
}
And the service model portion of my config file looks like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicSOAP_Binding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://basic.tip2tail.co.uk/"
binding="basicHttpBinding" bindingConfiguration="BasicSOAP_Binding"
contract="basicsoap_ref.BasicSOAP_PortType" name="MyServicesSoap" />
</client>
</system.serviceModel>
I generated a proxy via this command -
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config https://service100.emedny.org:9047/MHService?wsdl
and then copied the elements from the resulting app.config into the app.config file of an existing project.
When I try to access the client in that config file via-
MHSClient serviceProxy = new MHSClient("MHSPort");
it should reference the second client below:
<client>
<endpoint address="https://webservices.hmsa.com/EDI27X/cstc/Hipaa27XService.svc"
binding="customBinding"
bindingConfiguration="wsHttpEndpoint"
contract="HIPAA27XServiceContract"
name="wsHttpEndpoint" />
<endpoint address="https://12.23.28.113:9047/MHService"
binding="customBinding"
bindingConfiguration="MHService_MHSPort"
contract="MHS"
name="MHSPort" />
</client>
but instead I get the error;
Could not find endpoint element with name 'MHSPort' and contract 'MHS' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.'
If I go to definition of MHSClient, it takes me to the proxy.cs file and this line;
public partial class MHSClient : System.ServiceModel.ClientBase, MHS
solved with the following-
endptAddress = new EndpointAddress(new Uri("uri"/xxxx"), EndpointIdentity.CreateDnsIdentity("xxxxxx"), addressHeaders);
MHSClient serviceProxy = new MHSClient(b, endptAddress);
solved with the following-
endptAddress = new EndpointAddress(new Uri("uri"/xxxx"), EndpointIdentity.CreateDnsIdentity("xxxxxx"), addressHeaders);
MHSClient serviceProxy = new MHSClient(b, endptAddress);
#Guanxi gave me the clue when asking about endpoint address from the config file. Once I created the endpoint address then I could instantiate/create the service using the correct overload;
var b = new CustomBinding() as the first argument and for the second argument,
the correct endpoint address.
complicated - WS-Security - IBM Websphere server interop <-> wcf client within the context of various .NET and Visual Studio implementations of web services... oh my
You probably need to set the ConfigurationName property of the ServiceContractAttribute above the service contract interface, ConfigurationName should match your contract name.
'VB.NET:
Imports System.ServiceModel
<ServiceContract([Namespace]:="http://yournamespace", ConfigurationName:="MHS")> _
Public Interface MHS
//C#:
using System.ServiceModel;
[ServiceContract(Namespace="http://yournamespace", ConfigurationName="MHS")]
public interface MHS
Look at the auto generated code here:
MSDN: How to: Create a Windows Communication Foundation Client
Also worth looking at:
MSDN: ServiceContractAttribute Class
I'm developing a WCF service that has a contract called MyApp.IOperationService.
<service name="MyApp.OperationService">
<endpoint address="OperationService" binding="basicHttpBinding" contract="MyApp.IOperationService" />
</service>
For the service behaviour I used InstanceContextMode = InstanceContextMode.Single and ConcurrencyMode = ConcurrencyMode.Multiple because the application uses a shared physical resource.
I needed an administrative interface for this service and first I added a new contract within the same service. This approach didn't appeal to me because the administrative contract was exposed, through the metadata, to the clients using the operation contract.
Then I opted for creating another service altogether.
<service name="MyApp.AdminService">
<endpoint address="Admin" binding="netTcpBinding" contract="MyApp.IAdminService" />
</service>
This service has one operation, called Login, that propagates the pincode to the OperationService object.
namespace MyApp
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = false)]
public class AdminService : IAdmin
{
MyApp.OperationService objOperationService = null;
public AdminService(MyApp.OperationService objOperationService)
{
m_objOperationService = objOperationService;
}
public void Login(string pincode)
{
m_objOperationService.Login(pincode);
}
}
}
In a self-hosting environment I create a MyApp.OperationService object, then pass this object to the constructor of MyApp.AdminService. For IIS hosting, I discovered that I need to use WCF extensibility points and implement an IInstanceProvider, then use a ServiceHostFactory.
At this point I stopped and wondered if this will work at all, given that my AdminService expects an already created MyApp.OperationService that IIS controls, and it already seems awfully complicated for my humble purpose.
The question is if this (administrative contract/interface for an existing service that is not exposed through the metadata) can be achieved in another way?
Thank you.
I couldn't find a way to solve the problem, except using WCF extensibility points. I used Microsoft.Practices.Unity to manage the services through IoC, then used the Factory property in the .svc file.
I'm looking for minimal example of WCF Named Pipes (I expect two minimal applications, server and client, which can communicate via a named pipe.)
Microsoft has the briliant article Getting Started Tutorial that describes WCF via HTTP, and I'm looking for something similar about WCF and named pipes.
I've found several posts in the Internet, but they are a little bit "advanced". I need something minimal, only mandatory functionality, so I can add my code and get the application working.
How do I replace that to use a named pipe?
<endpoint address="http://localhost:8000/ServiceModelSamples/Service/CalculatorService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
contract="ICalculator" name="WSHttpBinding_ICalculator">
<identity>
<userPrincipalName value="OlegPc\Oleg" />
</identity>
</endpoint>
How do I replace that to use a named pipe?
// Step 1 of the address configuration procedure: Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service");
// Step 2 of the hosting procedure: Create ServiceHost
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(
typeof(ICalculator),
new WSHttpBinding(),
"CalculatorService");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
How do I generate a client to use a named pipe?
I just found this excellent little tutorial. broken link (Cached version)
I also followed Microsoft's tutorial which is nice, but I only needed pipes as well.
As you can see, you don't need configuration files and all that messy stuff.
By the way, he uses both HTTP and pipes. Just remove all code lines related to HTTP, and you'll get a pure pipe example.
Try this.
Here is the service part.
[ServiceContract]
public interface IService
{
[OperationContract]
void HelloWorld();
}
public class Service : IService
{
public void HelloWorld()
{
//Hello World
}
}
Here is the Proxy
public class ServiceProxy : ClientBase<IService>
{
public ServiceProxy()
: base(new ServiceEndpoint(ContractDescription.GetContract(typeof(IService)),
new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyAppNameThatNobodyElseWillUse/helloservice")))
{
}
public void InvokeHelloWorld()
{
Channel.HelloWorld();
}
}
And here is the service hosting part.
var serviceHost = new ServiceHost
(typeof(Service), new Uri[] { new Uri("net.pipe://localhost/MyAppNameThatNobodyElseWillUse") });
serviceHost.AddServiceEndpoint(typeof(IService), new NetNamedPipeBinding(), "helloservice");
serviceHost.Open();
Console.WriteLine("Service started. Available in following endpoints");
foreach (var serviceEndpoint in serviceHost.Description.Endpoints)
{
Console.WriteLine(serviceEndpoint.ListenUri.AbsoluteUri);
}
Check out my highly simplified Echo example:
It is designed to use basic HTTP communication, but it can easily be modified to use named pipes by editing the app.config files for the client and server. Make the following changes:
Edit the server's app.config file, removing or commenting out the http baseAddress entry and adding a new baseAddress entry for the named pipe (called net.pipe). Also, if you don't intend on using HTTP for a communication protocol, make sure the serviceMetadata and serviceDebug is either commented out or deleted:
<configuration>
<system.serviceModel>
<services>
<service name="com.aschneider.examples.wcf.services.EchoService">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/EchoService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors></serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Edit the client's app.config file so that the basicHttpBinding is either commented out or deleted and a netNamedPipeBinding entry is added. You will also need to change the endpoint entry to use the pipe:
<configuration>
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IEchoService"/>
</netNamedPipeBinding>
</bindings>
<client>
<endpoint address = "net.pipe://localhost/EchoService"
binding = "netNamedPipeBinding"
bindingConfiguration = "NetNamedPipeBinding_IEchoService"
contract = "EchoServiceReference.IEchoService"
name = "NetNamedPipeBinding_IEchoService"/>
</client>
</system.serviceModel>
</configuration>
The above example will only run with named pipes, but nothing is stopping you from using multiple protocols to run your service. AFAIK, you should be able to have a server run a service using both named pipes and HTTP (as well as other protocols).
Also, the binding in the client's app.config file is highly simplified. There are many different parameters you can adjust, aside from just specifying the baseAddress...
I created this simple example from different search results on the internet.
public static ServiceHost CreateServiceHost(Type serviceInterface, Type implementation)
{
//Create base address
string baseAddress = "net.pipe://localhost/MyService";
ServiceHost serviceHost = new ServiceHost(implementation, new Uri(baseAddress));
//Net named pipe
NetNamedPipeBinding binding = new NetNamedPipeBinding { MaxReceivedMessageSize = 2147483647 };
serviceHost.AddServiceEndpoint(serviceInterface, binding, baseAddress);
//MEX - Meta data exchange
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
serviceHost.Description.Behaviors.Add(behavior);
serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), baseAddress + "/mex/");
return serviceHost;
}
Using the above URI I can add a reference in my client to the web service.