I have a WCF service in a service library and I'm trying to host it in a WCF service application. I modified the .svc file accordingly
<%# ServiceHost Language="C#" Debug="true" Service="Mandrake.Service.OTAwareService" Factory="Mandrake.Service.OTServiceHostFactory" %>
And I added the stuff that was originally in the service library's app config to the service application's web.config file. I thought it overrides the settings defined in the library's app.config, but it turned out if I remove the app.config file from the library and host the service application on IIS with the web.config containing the necessary endpoint setup (which worked previously) the service doesn't get started and says I have no endpoint defined.
My web.config's servicemodel section is as follows:
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Mandrake.Service.OTAwareService"
factory="Mandrake.Service.OTServiceHostFactory"
relativeAddress="OTService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="StandardBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Mandrake.Service.OTAwareService" behaviorConfiguration="StandardBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8062/OTService"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
<endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Is there a way I can host this service from the service library in my service application?
Most probably you may not have net.tcp binding enabled on website where you are hosting your service application. Check in iis if net.tcp is there in list of bindings.
Related
I have a WCF Service which I am hosting in a windows service. The Windows host service has an App.config to consume a service endpoint and the service has an App.config which exposes the metadata endpoints. When the service is deployed via the VS development system it all works great. With a Web Browser loaded, the http://localhost:9001/ url resolves to the metadata webpage exposing the wsdl link for the service. It even works with the WCF Test Client as well and I can send the service messages and it responds.
However, with the projectInstaller loaded on the hosted service in VS and deployed outside of the VS development system, I can no longer access the http://localhost:9001/ metadata endpoint when the hosted service is deployed in Windows. The service is started and running, but the endpoint doesn’t respond. The Service is deployed from the debug folder using the “sc create binpath= “Service.exe” start= auto” command. Maybe this is not the correct way to deploy it, not sure or maybe my app.Config files are not correct or being referenced correctly. Could someone let me know the process for this and maybe verify that my app.Config files are correct for both the windows Host and Service side. This is pretty tricky to configure, so any help is appreciated.
Window host service App.config to consume the endpoints:
<system.serviceModel>
<client>
</client>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_WindowsService" maxReceivedMessageSize="20000000" />
</basicHttpBinding>
</bindings>
<services>
<!-- Service endpoint to consume -->
<service name="WindowsService.Service">
<endpoint address="http://localhost:9001/Service" binding="basicHttpBinding"
contract="WindowsService.IService" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
Service Web.config to expose the endpoints:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_WindowsService" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="defaultbehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="defaultbehavior" name="WindowsService.Service">
<!-- Base address for exposing Metadata and Service -->
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/" />
</baseAddresses>
</host>
<!-- Metadata service endpoint to expose -->
<endpoint address="" binding="mexHttpBinding" contract="IMetadataExchange" />
<!-- Service contract endpoint to expose -->
<endpoint address="Service" binding="basicHttpBinding" contract="WindowsService.IService" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
I hosted my WCF Service using Windows Service, but when I call the WCF method I get the following error:
System.ServiceModel.ServerTooBusyException: The HTTP service located
at
http://localhost:8733/Design_Time_Addresses/RahatWcfServiceLibrary/ServerDateTime/
is too busy. ---> System.Net.WebException: The remote server returned
an error: (503) Server Unavailable.
The App.Config in my WCF Service and Windows Service is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="RahatWcfServiceLibrary.ServerDateTimeBehavior" name="RahatWcfServiceLibrary.ServerDateTime">
<endpoint address="" binding="wsHttpBinding" contract="RahatWcfServiceLibrary.IServerDateTime">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/RahatWcfServiceLibrary/ServerDateTime/mex" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RahatWcfServiceLibrary.ServerDateTimeBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="60" maxConcurrentSessions="60"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I solved the issue by adding '/mex' at the end of endpoint address in App.Config file in Windows Application that consumes the service.
<endpoint address="http://localhost:8733/Design_Time_Addresses/RahatWcfServiceLibrary/ServerDateTime/mex"
I have a WCF Service running on my local machine
Everything themes to be running okay
Question is
if i can Invoke this WCF Service on my local machine browser
why it is not available on other machines
what i have tried :
my service address was localhost : port on the other machine i replaced the localhost with the ip of the machine where my WCF service is running and it didn't work
in my App.config i changed the baseaddress as you can see below from localhost to the machine ip and it didn't work either
i created a web application and call my service using getJson and it worked on my local machine browser and not on any of the other machine it loads the whole page and gives me error on getJson
what i am missing here ??? i don't know
IService1.cs
[OperationContract]
[WebGet(UriTemplate = "GetName/{name}",
ResponseFormat = WebMessageFormat.Json)]
List<Eval> GetName(string name);
App.config
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"></binding>
</webHttpBinding>
</bindings>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://192.168.1.5:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="WcfServiceLibrary1.IService1" behaviorConfiguration="web">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
WCF Test Client
Browser
It might be that firewall is stopping service call. Open inbound connection on port 8733 on machine where WCF is hosted. In case of Windows, open the Windows Firewall with Advanced Security dialog box, in the left pane, click Inbound Rules, and then, in the right pane, click New Rule and select Port option.
I try to Host WCF in a Windows Service Using TCP using this article:
http://msdn.microsoft.com/en-us/library/ff649818.aspx
and after all the steps successfully pass include running the service i try to Add a WCF Service Reference to the Client so i created console application project and after try to add reference to my service i got this error:
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.0072566. 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.
This is my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I also try netstat -ap tcp and cannot find my service connaction
I have the following configuration file for WCF service. There is a host defined in the config. Still, when I print the service address from the client, it does not know about the host. The printed result is:
http://localhost:3187/Service1.svc/MyFolder
Why doesn’t it take into account the host name? What modification do we need to do for it?
Note: I am running from VS 2010 for running service and client website.
Service1Client myClientService = new Service1Client();
Response.Write(myClientService.Endpoint.Address);
Client Configuration (Autogenerated by Visual Studio)
<client>
<endpoint address="http://localhost:3187/Service1.svc/MyFolder"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="MyWCFReference.IService1" name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="U16990#ustr.com" />
</identity>
</endpoint>
</client>
The server side configuration is:
<services>
<!--MyService-->
<service name="MyWCFServiceApplication.MyService"
behaviorConfiguration="WeatherServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/ServiceModelSamples/FreeServiceWorld"/>
</baseAddresses>
</host>
<endpoint address="MyFolder"
binding="wsHttpBinding"
contract="MyWCFServiceApplication.IService1" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
When a WCF service is hosted in an ASP.NET process, through either IIS or the ASP.NET Development Server (a.k.a Cassini), the baseAddresses setting in the service's configuration file is ignored since the service will always be reachable through the URL of the SVC file.
The URL you're seeing on the client is therefore correct:
http://localhost:3187/Service1.svc/MyFolder
As you can see, the base address of the service becomes the URL of the SVC file on the web server.
You're talking about a WCF client - yet, the config you posted only contains config for a service (the server side) ... (the <services> section).
I can't see any client configuration in what you posted - there ought to be a <client> section in your config somewhere