I'm working on a website that consumes a WCF service hosted in a different app pool, and every time the WCF service's app pool recycles I get a 503 when I'm using the website:
[WebException: The remote server returned an error: (503) Server Unavailable.]
System.Net.HttpWebRequest.GetResponse() +6440728
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +55
[ServerTooBusyException: The HTTP service located at http://cr.genesis.dev/Genesis/RepositoryService.svc is unavailable. This could be because the service is too busy or because no endpoint was found listening at the specified address. Please ensure that the address is correct and try accessing the service again later.]
...
When I try to access the service directly in my web browser it gives me a 503 the first time, but then it works after that (presumably it's causing the application to start?) I'm wondering why the website isn't waking up the web service - even if I try loading a page several times I still get a 503...
I'm using Windsor WCF Integration if that makes any difference, using LifestylePerWebRequest for my client and LifestylePerThread for my service.
This is my config for the service:
<system.serviceModel>
<services>
<service name="Genesis.Repository.Service.RepositoryService" behaviorConfiguration="repositoryServiceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://cr.genesis.dev/Genesis/" />
</baseAddresses>
</host>
<endpoint name="basicHttpBinding"
address="RepositoryService.svc"
binding="basicHttpBinding"
contract="Genesis.Repository.Service.IRepositoryService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="repositoryServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
And the client:
<system.serviceModel>
<client>
<endpoint name="basicHttpBinding"
address="http://cr.genesis.dev/Genesis/RepositoryService.svc"
binding="basicHttpBinding"
contract="Genesis.Repository.Service.IRepositoryService" />
</client>
</system.serviceModel>
Any suggestions would be appreciated!
Looks like I was making it more complicated than it needed to be - I'd been getting exceptions saying it couldn't listen on http://+:80 which is why I'd played around with netsh permissions and made it listen on /Genesis.
Turns out I can just make it listen on / and specify .Hosted() when registering it with Windsor to tell it to let IIS host it (which is exactly how it was before I installed the WcfFacility!)
Lesson learned, sometimes you just have to go back to basics and things will work as intended!
If you found the "(503) Server Unavailable error" then first point of check is that server is running or not. For this go to the IIS and check the web site is on or off.
Related
Hej,
I feel like a complete idiot but I don't seem to find an answer.
I'm selfhosting a WCF service in a console application.
This is working like a charm, I've done it a million times :)
Consuming this service from another console application or by using wcftestclient is no problem at all.
But when trying to browse to the service I get "strange" behavior.
The service is hosted at http://localhost:50666/MyService.Foo/BarServiceHttp (with base-address http://localhost:50666/MyService.Foo).
So when browsing to http://localhost:50666/MyService.Foo/BarServiceHttp does return a HTTP 400 error in the browser.
Browsing to the base-address gives the output that I expected at the full address.
What's going on? (The space after the http was inserted to bypass the warning concerning localhost...)
Here is the server config:
<service name="FooService" behaviorConfiguration="FooBarServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:50666/MyService.Foo" />
</baseAddresses>
</host>
<endpoint address="BarServiceHttp"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBindingConfiguration"
contract="IBarService" />
<endpoint address="BarServiceHttp/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
<behavior name="FooBarServiceBehavior">
<!-- Enable MEX http get for this service. -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
You are getting an HTTP 400 error because you are trying to access an endpoint directly. The endpoint expects SOAP request, but instead browser sends HTTP GET request, which can't be handled by the endpoint. You should use base address when browsing the service, since the metadata and the help page, that you see in the browser, live here:
http://localhost:50666/MyService.Foo
First, I am not good in WCF.
I have a WCF service hosted in WindowsService.
Since sometime the service stoped to run because of the exception:
HTTP could not register URL http://+:8092/MyService/ because TCP port 8092 is being used by another application.
Nothing uses this port, it says the same about any port I tried.
SSL certificate is configured.
There are many machines that can start this service, but the most required (customer's) machine cannot.
I saw many posts in this site or anywhere else, but cannot find a solution.
I never see the post like "It helped me".
I am stuck several days already, help please.
Below the data from config file:
<system.serviceModel>
<services>
<service name="MyCompany.MyApp.MyAppService" behaviorConfiguration="MetadataSupport">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8092/MyAppService" />
<add baseAddress="net.tcp://localhost:8093/MyAppService" />
<add baseAddress="net.pipe://localhost/" />
</baseAddresses>
</host>
<endpoint binding="wsDualHttpBinding" contract="MyCompany.MyApp.IMyAppService" />
<endpoint binding="netTcpBinding" contract="MyCompany.MyApp.IMyAppService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="tcpmex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataSupport">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True" httpGetUrl="" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug httpHelpPageEnabled="True" includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
You are using WCF duplex communication with wsDualHttpBinding. In this case, WCF creates a HTTP socket on port 8092 to service client callbacks. Clearly the client was conflicting with IIS 5.X. (I guess you have XP and IIS 5.x)
To resolve this problem you have to provide a clientBaseAddress in the binding configuration on the client and specify a different port.
Sample client configuration:
I hope that this is really the problem in your machine, please notify me about the results of this solution.
Good luck :-)
Try running the windows service as someone with admin privileges. Certain versions of Windows (2008/Vista and up) are picky about who can open ports. If that helps, then you certainly don't want to actually run the service as an admin, but it at least points you in the permissions direction.
Also, you mention an SSL cert, but it is an 'http' url, not 'https'. That seems unusual.
I suggest to do the following diagnostics steps:
Try hosting the WCF Service in a Self-Host manner (Console Application):
use the class HttpServiceHost
use this binding: var binding = new HttpBinding(HttpBindingSecurityMode.Transport);
AddServiceEndpoint(typeof(YourServiceClass),binding,"https://url...");
If it works for you it seems that you have problems in configuring the WCF service to work under Managed-Windows Service.
Lets me know your results :-)
I've set up a WCF service to require NTLM authentication using the following configuration:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="BinarySecurityBinding">
<binaryMessageEncoding/>
<httpTransport authenticationScheme="Ntlm"/>
</binding>
</customBinding>
</bindings>
<services>
<service name="Services.LogisticsServices" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="customBinding" bindingConfiguration="BinarySecurityBinding" contract="Services.ILogisticsServices" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I did this so that the applications that consume the web service are forced to log in because all my service's operations use impersonation ([OperationBehavior(Impersonation = ImpersonationOption.Required)]).
In IIS 7 I've enabled anonymous and Windows authentication.
When I visit http://test.server/LogisticsServices.svc, which hosts the service described above, I can see the default service description page anonymously. However, when Visual Studio tries to access http://test.server/LogisticsServices.svc/$metadata to generate a client proxy, the server is responding with HTTP code 401 and expecting authentication. Not only would I've expected the metadata to be available anonymously, but additionally, the server is not accepting the credentials I am giving it (even though, I know for a fact that they are correct).
Testing different configuration, I tried removing the authenticationScheme from my binding's transport, just to be able to generate the client proxy, but that results in an exception because the service's operations require impersonation ([OperationBehavior(Impersonation = ImpersonationOption.Required)]).
What am I missing in my service's configuration that would make the service's metadata available anonymously? I'm also open to suggestions if I'm approaching the whole thing wrong.
here is a similar discussion:
Getting an Security setting exception while accessing a WCF service
One way around this is not to use the autogenerated proxies.
In cases where we have control over both the server and the client we have found that it is much more productive to avoid using the autgenerated proxies.
A screencast of how to do this can be found here: http://www.dnrtv.com/default.aspx?showNum=122
You could try imperative instead of declarative model, see: http://msdn.microsoft.com/en-us/library/ms730088.aspx
Like the title says, we need to set up WCF services between a .NET app, and a Adobe AIR app. We don't want to run IIS on the machine, and would much prefer to install and run the WCF services hosted within a windows service.
However, I am uncertain of doing that will let us use HTTP as the transport, of does that only work within IIS? I was able to set things up to use the TCP transport, but that doesn't interop with AIR nearly as nice as using HTTP.
EDIT: Some test code I've been using to see if this works:
Regular console app:
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(TestService)))
{
host.Open();
}
Console.WriteLine("Waiting...");
Console.ReadLine();
}
TestService is a simple HelloWorld type service.
In the App.Config:
<configuration>
<system.serviceModel>
<services>
<service name="WCFExample2.TestService" behaviorConfiguration="WCFExample2.TestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WCFExample2/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="wsHttpBinding" contract="WCFExample2.ITestService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFExample2.TestServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
You should have no trouble setting up a Windows NT Service which hosts your WCF service and exposes HTTP endpoints - no need for IIS (but the WCF runtime will use the http.sys kernel mode driver).
Have you tried and failed? If so - can you show us what you had, and how and where it failed?
As a bare minimum, you'd probably want to have something like this config on your service side:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="Default"
sendTimeout="00:05:00"
maxBufferSize="500000"
maxReceivedMessageSize="500000" >
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Namespace.MyWCFService"
behaviorConfiguration="Default">
<host>
<baseAddresses>
<add baseAddress="http://MyServer:8282/MyWCFService/"/>
</baseAddresses>
</host>
<endpoint
address="basic"
binding="basicHttpBinding" bindingConfiguration="Default"
contract="Namespace.IMyWCFService" />
</service>
</services>
</system.serviceModel>
Of course, you might need to tweak things like the timeout settings, buffer size settings etc. on your binding, the security mode, and quite possibly other settings as you need them to be.
Marc
You could skip all the config and use the WebServiceHost class (which will do it all for you in a fairly standard way). Get that working then look into tailoring the config manually to meet any extra requirements you may have.
All the info you need is here WebServiceHost on MSDN it's a very straightforward way to get started on a custom (i.e. non IIS) hosted http service.
Mike
Apart from the config file settings one more thing to consider.
If you selfhost in a windows service, a http endpoint then
Make the service login account a local admin on the machine
or
You have to register the service account for the http namespace with http.sys.
This step has to be done by a local admin but only once in each machine. You can use the HttpSysCfg tool to do this in XP/win 2003. For vista/win 2008 use netsh.
WCF - There was no endpoint listening at net.tcp://myserver:9000/SearchQueryService/Querier.svc that could accept the message.
I have the net.tcp protocol enabled on the IIS application
Windows firewall is off
The net.tcp binding is set to port 9000 for the entire IIS application.
My web.config is very standard:
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="false"
logMessagesAtTransportLevel="true" />
</diagnostics>
<services>
<service behaviorConfiguration="SearchQueryServiceBehavior"
name="Search.Querier.WCF.Querier">
<endpoint address="mex" binding="mexHttpBinding" name="mexHttpEndpoint"
contract="IMetadataExchange" />
<endpoint binding="netTcpBinding" bindingConfiguration=""
name="netTcpEndpoint"
contract="Search.Querier.WCF.IQuerier" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SearchQueryServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
And this very setup works on one server but not the other...
What could be the problem?
Both servers, the working and non-working one are running IIS7.
The only difference is the working box is Vista64 Sp2 and non working one is W2k864.
I think that you are missing the net.tcp in the "Enable Protocols" list in the advanced settings of the site.
Do you have .net 3.5 installed on the w2k864 machine? After you install it, did you run aspnet_iisreg?
Check the asp.net settings in IIS and ensure it is set to use 2.0
Can you provide any more information?
Also try to use your ip rather than a host name. e.g. 192.168.1.100 instead of myserver
When you browse to the service (http://myserver/SearchQueryService/Querier.svc), do you get any error messages?
I also noticed that your client is calling the net.tcp endpoint on port 9000. Does this configuration matches the IIS net.tcp configuration? In a default configuration, a call to your service should be pointed to net.tcp://myserver/SearchQueryService/Querier.svc
It is possible that there is another application configured to be listening on the same port, you can see this being mentioned here as well - https://stackoverflow.com/a/7254861/4446128, if that is the case likely both applications on the same port are not working. I wish there would be a better error message when that happen as it took me forever to figure out (I had to deal with many apps talking over net.tcp), I hope this info will be helpful for anyone who still deals with WCF.