Using the example from github, setting up a simple wcf service hosted in a windows service works fine. However, when I add another servicecontract implementation, I'm not able to host this under the same baseAddress, i.e from app.config:
<service name="ContractService" behaviorConfiguration="WebServicesBehavior">
<host>
<baseAddresses >
<add baseAddress="baseUri"/>
</baseAddresses>
</host>
<endpoint address="addr1" binding="wsHttpBinding" contract="IContract1"/>
<endpoint address="addr2" binding="wsHttpBinding" contract="IContract2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
I'm able to host 2 services, using this example, however I would like to achieve to have multiple service contracts hosted within the same baseAddress and possible multiple endpoints, but my search for solutions to this have left me stranded.
This setup works:
<services>
<service name="ContractService1" behaviorConfiguration="WebServicesBehavior">
<host>
<baseAddresses >
<add baseAddress="http://localhost:8082/Services/"/>
</baseAddresses>
</host>
<endpoint address="addr1" binding="wsHttpBinding" contract="IContract1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="ContractService2" behaviorConfiguration="WebServicesBehavior">
<host>
<baseAddresses >
<add baseAddress="http://localhost:8083/Services/"/>
</baseAddresses>
</host>
<endpoint address="addr2" binding="wsHttpBinding" contract="IContract2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
The wireup using ninject is the same as in the github example.
Is there a way to achieve multiple endpoint using selfhost wcf with ninject?
You can have multiple services on the same port by specifying different baseAddresses for the same port.
Append the address from the endpoint definition to the base address for each of the services like so:
<add baseAddress="http://localhost:8083/Services/addr1"/>
<endpoint address="" binding="wsHttpBinding" contract="IContract1"/>
Related
Have above 5 WCF projects. In which 4 has to be hosted as windows service and 1 in IIS. All in the same machine.
For each of the 4 WCF projects, I require 4 Windows service projects to host separately. To minimize the number of projects to be maintained, I am thinking of one single windows service to install all the 4 WCF projects for easy maintainability. Anyway apart from OnStart and OnStop I call the wcf and no other logics are there.
The challenges I see are, each Windows service requires the same app config file as used in WCF projects. If I would do this dynamically by getting the service name from app settings, How will I load the app.config file of different wcf projects to host as windows service during run time.
Is this feasible ? If so how can i achieve this ?
Yes, it's possible, you just need to configure each one endpoint in your config file. How to do that:
Windows Service WCF hoster is ServiceHost class, so you need to create 4 hosts for every contract.
var serviceHost = new ServiceHost(typeof(CommunicationManagement));
serviceHost.Open()
Now you can configure every your service endpoint in services section:
<system.serviceModel>
<services>
<service name="Communication.Service.CommunicationManagement">
<endpoint
binding="netTcpBinding"
bindingConfiguration="myBinding"
contract="Communication.Service.ICommunicationManagement"
name="CommunicationManagement">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="MEX" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Communication/Service/CommunicationManagement" />
</baseAddresses>
</host>
</service>
<service bname="Communication.Service.Managers.PhoneAdatpersManager">
<endpoint
binding="netTcpBinding"
bindingConfiguration="myBinding"
contract="Communication.IPhoneAdministration"
name="PhoneAdministration">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="MEX" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Communication/Service/PhoneAdministration" />
</baseAddresses>
</host>
</service>
</services>
<system.serviceModel>
Above you can see PhoneAdatpersManager and CommunicationManagement services, they hosting in a single Windows Service and works together on 8000 port (but you can use different ports).
Is it possible to implement multiple services with the same scheme HTTP?
Like this:
<system.serviceModel>
<services>
<service name="MyServiceBecouseError.MyNameService" behaviorConfiguration="mexBehaviors">
<endpoint address="xxx" binding="basicHttpBinding" contract="MyServiceBecouseError.IMyNameService"></endpoint>
<endpoint address="yyy" binding="basicHttpBinding" contract="MyServiceBecouseError.IMyNameServiceSecond"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/eff-off"/>
<add baseAddress="http://localhost:5555/eff-off"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Yes, it's possible.
As a result you'll have your two services listening at:
http://localhost:8080/eff-off/xxx
http://localhost:8080/eff-off/yyy
http://localhost:5555/eff-off/xxx
http://localhost:5555/eff-off/yyy
And of course metadata exchange endpoints will be there as well.
I have a C# WCF Service Library that's running properly locally. A client running locally was able to see the service and consume it.
However, when I tried hosting the service in a WebRole and deploying it on Azure, the client was never able to connect to it successfully the same way it did locally! The way I did it was as follows:
// The WCF Service library is in namespace: Root.Library
Uri url = new Uri("http://xxx.cloudapp.net:8099/DealerService"); // tried also without "DealerService" but still didn't work
ServiceHost host = new ServiceHost(typeof(Root.Library.DealerService), url));
host.AddServiceEndpoint(typeof(Root.Library.IDealerService), new WSHttpBinding(), "DealerService");
ServiceMetadataBehavior dealerMetaBehavior = new ServiceMetadataBehavior();
dealerMetaBehavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(dealerMetaBehavior);
host.Open();
And inside Root.Library, the app.config:
<service name="Root.Library.DealerService">
<endpoint address="" binding="wsHttpBinding" name="dealer" contract="Root.Library.IDealerService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://xxx.cloudapp.net:8099/" />
</baseAddresses>
</host>
</service>
I also added an Endpoint to the WebRole config (Type:Input, Protocol:http, PublicPort:8099)
Can someone tell me what the problem might be??? this is really confusing me!
Thanks a lot!
You should just be able to change the port based on the csdef file
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="8888" />
</Endpoints>
Saqib Ullah has a post on geekswithblogs that shows more information: http://geekswithblogs.net/technetbytes/archive/2011/04/25/145035.aspx
In the solution, 4 projects : Business, the WCFService and the WCFServiceHost (a windows service) and a client
When I work in the solution, no problem, I can discover and create the proxy in the client.
When I install the host service, I start it but impossible to discover and create the proxy from visual studio with this : net.tcp://localhost:9100/MyApplicationWcf
Any idea ?
Thanks,
update #1
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyApplicationWcf.MyClassWcf">
<endpoint address="net.tcp://localhost:9100/MyClassWcf"
binding="netTcpBinding"
bindingConfiguration=""
name="MyClassWcf_Tcp"
contract="MyApplicationWcf.MyClassWcf" />
<endpoint name="mexHttpBinding"
contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
</system.serviceModel>
</configuration>
If you want to discover the service over net.tcp, you will need to define a MEX endpoint (metadata exchange) that uses the mexTcpBinding.
<behaviors>
<serviceBehaviors>
<behavior name="MexBehavior" >
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="mexBinding" portSharingEnabled="true">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="YourServiceImpl"
behaviorConfiguration="MexBehavior">
<host>
<baseAddresses>
<add baseAddress ="net.tcp://localhost:9100/MyApplicationWcf/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding"
contract="IYourServiceContract" />
<endpoint address="mex"
binding="mexTcpBinding" bindingConfiguration="mexBinding"
contract="IMetadataExchange" />
</service>
</services>
Do you have that??
Check out: How to: Publish Metadata for a Service Using a Configuration File for more information.
This is the configuration file while hosting the service, here i hosted service using ip 127.0.0.1:36345, here service is not accessible using netTcpBinding
when i hosted the using the exact ip of server (192.168.1.47:36345) it works..
what could be possible reason and solution?
<services>
<service behaviorConfiguration="metadataSupport" name="WCFSvc.WCFService">
<endpoint binding="wsDualHttpBinding" bindingConfiguration="wsDualHttp"
contract="WCFSvc.IWCFService" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTcp"
contract="WCFSvc.IWCFService" />
<endpoint binding="netNamedPipeBinding" contract="WCFSvc.IWCFService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:26345/WCFSvc" />
<add baseAddress="net.tcp://127.0.0.1:36345/WCFSvc" />
<add baseAddress="net.pipe://localhost/DataService/Service.svc" />
</baseAddresses>
</host>
</service>
</services>
Could be several things, here are a few that you could try:
Is there any local firewall on the machine blocking the request?
Is there a confilct with the net.pipe configuration?
Is there something in the binding configuration that could be causing the problem?
What error are you getting? Is there any error being written to the eventlog?