I have around 15-20 services - each service has its own contract and implementation file. I want to host all these service in a console app so that it will be easier to debug during development.
Project structure
Services - Solution
ServiceContracts - Project
Implementation - Project
ServiceHost - Windows Service project -- Already inplace and working fine..
ServiceConsoleHost - Project - Currently working on it.
I have an app.config file in the ServiceConsoleHost project here the sample text from config file...
<service name="TestpricingService" behaviorConfiguration="HostBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/testService/pricingService"/>
</baseAddresses>
</host>
<!-- use base address provided by host -->
<endpoint address="net.tcp://localhost:820/testService/pricingService"
binding="netTcpBinding"
bindingConfiguration="HostBinding"
contract="Test.Services.Contracts.IpricingService" />
<!-- the mex endpoint is exposed at http://localhost:8000/testService/purchasing/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<behaviors>
<serviceBehaviors>
<behavior name="HostBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior name="PooledHostBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<ObjectPoolingServiceBehavior minPoolSize="0" maxPoolSize="5" idleTimeOut="30000"/>
</behavior>
</serviceBehaviors>
</behaviors>
Thanks in advance...
You are probably looking for self-hosted services. See MSDN Reference on self-hosting using ServiceHost.
Also take a look at enumerating WCF configuration bindings. Here is an SO post which describes enumerating WCF service and endpoint bindings.
as everyone mentioned you need 15 ServiceHosts to host 15 services. However they are not blocking. If you notice the MSDN code just sits waiting for a keypress whilst the service is running. This means all the service code is running on separate threads. So creating and hosting 15 services is not an issue. You dont need a "loop" as that is already handled once you do ServiceHost.Open().
Related
I have a test WCF service that I hosted on IIS. I added a new application to the default website and used default app pool to host my test service. I am able to browse the .svc file from the content view in IIS and the success page along with a link to wsdl opens up on Windows IE. However, on clicking the wsdl link, a HTTP 404(Not found) error is thrown.(everything is on my localhost being accessed internally)
I have added the metadata endpoint and this is the relevant portion of my web.config file.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehaviour" name="ClassLibrary1.HelloWorldService">
<endpoint address="HelloService" binding="basicHttpBinding" bindingConfiguration=""
contract="ClassLibrary1.IHelloWorldService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:17000"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Can someone please guide me about what I can be missing? Could it be a permissions issue or anything else?
Thanks.
There is no need to add the base address to service contract which will be provided by the IIS web server.
The default wcf application configuration enable the service metadata and we are able to access the metadata by the svc page or we directly use the following url.
http://localhost:90/Service1.svc?wsdl
Feel free to contract me If the problem still exists.
I am trying to deploy a wcf service I have created in Visual studio.
I am almost positive it is a configuration issue in either the wcf service config or in IIS itself.
The config I am using in the service is as follows:
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CandidateServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="SurveyService.SurveyService" behaviorConfiguration="CandidateServiceBehavior">
<endpoint address="/Survey/SurveyService" binding="netTcpBinding" name="CandidateServiceEndPoint" contract="Prometric.Census.SurveyService.ISurveyService" />
<endpoint address="/Survey/SurveyService/mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
I deployed the service once from visual Studio and pointed a new site on IIS with the following settings pointing to the deployment folder
Then after this within IIS you can see the site is in an unknown status:
It is from here that I can't connect to the service or find if it is running or not. I have tried the command /an : find /i "9015" and found nothing so I assume the service is not even running.
If I where to change the bindings on the WCF service and IIS to use http instead everything works fine. (Should say using http is not an option)
Also on top of not getting the service up and running I'm unsure how to test the service as TCP, Am I able to just add a service reference as you would with a http sefvice? As you can see I am pretty new to the tcp side of things and if I have left out any vital information please let me know so I can inslude it in the question.
This might help you :
https://rohitguptablog.wordpress.com/2011/06/16/configuring-wcf-service-with-nettcpbinding/
I followed this guide to make a net.tcp wcf service and it went smoothly. Also, are you sure that your folder has the required privileges? It can be tricky to use another folder than wwwroot/inetpub
I have a simple WCF 4.0 service with some simple methods and a property with a getter that returns List. The service works fine when connected to programatically. The getter is decorated as are the other methods on the Interface that define the service contract.
My next move is to make the service accessible via the IE web browser so server/deployment admins can do a "smoketest" after service installation.
This works currently:
http://localhost/myservice.svc?wsdl
But I need to take things further and get this to work:
http://localhost/myservice.svc/SmokeTest
and have results show in the browser, SmokeTest is the property with a getter that does stuff and returns the List I want to show in the browser.
So far I can't figure out what my config should look like. All help appreciated.
This is all I have in the web.config for the service. The endpoint is myservice.svc:
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="myservice.worker" >
<endpoint address="" binding="basicHttpBinding" contract="myservice.IServicio" />
</service>
</services>
related question, an explanation of what can and can't be done:
Invoking WCF services through a browser
I'm generating WCF service using Biztalk. The code I get is this:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviorConfiguration">
<serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" externalMetadataLocation="" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkServiceInstance" behaviorConfiguration="ServiceBehaviorConfiguration">
<endpoint name="HttpMexEndpoint" address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<!--<endpoint name="HttpsMexEndpoint" address="mex" binding="mexHttpsBinding" bindingConfiguration="" contract="IMetadataExchange" />-->
</service>
</services>
</system.serviceModel>
Maybe it's not the most beautifull configuration, but it works. The problem is I don't know how to modify timeouts and message max size, because it has only mex endpoint. I'm surprised how this works at all with just mex endpoint.
So two questions are:
Why does this works at all?
What should I add to extend timeouts and message size?
I seem to recall the reason those settings aren't in the config file is because the binding configuration is stored in the receive location / send port settings in biztalk itself. So the way to set them is to change them from the receive location adapter configuration.
On my dev box I have a solution with 6 projects. It is a WCF(3 proj) and multiple biz projects (other 3).
When I copy the core WCF folder, it's bin and web.config I get an error message on the server saying that it cannot find the contract that is stated in the app.config section of the biz app with an app.config.
Where should I put this app.config? I tried to add the node to the web config but no go there.
If you're trying to host that services into a web application, you'll need to merge manually that individual app.config files (one for each WCF project) into your web.config file, under <system.serviceModel> section.
EDIT: You'll need something like this into your host configuration (web project?)
<system.serviceModel>
<services>
<service name="YourCompany.YourProject.YourService"
behaviorConfiguration="YourBehaviorConfiguration">
<endpoint address=""
binding="wsHttpContextBinding"
contract="YourCompany.YourProject.IYourService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="YourBehaviorConfiguration">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>