WCF - unable to stop net.tcp binding (hosted on IIS) - c#

I have working WCF service on IIS with configured net.tcp endpoint. After disable page on IIS I'm still able to run request to my service o.O.
Disabling application pool works as expected (service is no longer available).
<system.serviceModel>
<services>
<service name="xyz.Service.Authentication.Implementation.AuthenticationService">
<endpoint binding="netTcpBinding"
bindingConfiguration="NetTcpBinding"
contract="xyz.Service.Authentication.Model.IAuthenticationService"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding" sendTimeout="00:00:30"
transactionFlow="false"
portSharingEnabled="false"
maxReceivedMessageSize="18000">
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="Sign"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceAuthorization principalPermissionMode="UseWindowsGroups"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Is it a bug or a feature ?

I had similar problem and I found out that:
Stopping Web Site does not stop the net.tcp service
Disable App Pool disables service but does not free the port, port is still used by SMSvcHost.exe
Restarting after does not helps too.
The only way to free port ( to be used by something else ) was to delete net.tcp binding in IIS.
I spent time on this, because received wrong answers from net.tcp service. It took me while, to find out - it's not from my service, but from old disabled one. This could save time to someone else.

Related

Configure WCF as Named Pipe hosted on IIS7

I have two different WCF services hosted on IIS7. One is Database Service which is configured to run on namedpipe. The other service hosted on same machine is accessing the first service via named pipe and is configured to run on webhttp.
however when i call the database service from another service i get the following error
"There was no endpoint listening at "net.pipe://localhost/iSPYDBService" that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."
Database Service Config file Snippet
<system.serviceModel>
<services>
<service name="DBService.Service">
<endpoint address="net.pipe://localhost/iSPYDBService"
binding="netNamedPipeBinding"
contract="DBService.Contracts.IDBService"
bindingConfiguration="Binding1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<bindings>
<netNamedPipeBinding>
<binding name="Binding1"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
maxBufferPoolSize="524288"
maxBufferSize="65536"
maxConnections="10"
maxReceivedMessageSize="65536">
<security mode="Transport">
<transport protectionLevel="EncryptAndSign" />
</security>
</binding>
</netNamedPipeBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
The Other Service Calling the Database service via named pipe throws error as mentioned above.
ChannelFactory<DBService.Contracts.IDBService> pipeFactory =
new ChannelFactory<DBService.Contracts.IDBService>(
new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/iSPYDBService"));
pipeProxy = pipeFactory.CreateChannel();
var categories = pipeProxy.GetCategories();
Both services are hosted on IIS. i have already given the binding for net.pipe in database service and also add "http,net.pipe" in "enabled protocols".
You cannot use IIS Express.
In IIS (full, not express) ... go to your website.
Follow this bread crumb:
WCF Host Web Site > Manage Application > advanced Settings > Enabled Protocols
You probably have "http" or "http,net.tcp" already set.
Add "net.pipe" (with a comma before it)
As seen below. Note, do not add any spaces.
http,net.tcp,net.pipe
The magic is the correct value ("net.pipe") in this case.
You can read more about it here
Could not find a base address that matches scheme net.tcp
The following should help:
Clear the address in the service config like address=""
Edit the bindings of your site in IIS and add or update the site bindings of the net.pipe type and give the "Binding information" a proper name
Update your client config to address="net.pipe://PROPER_NAME/YOUR_SERVICE.svc"
Set the security mode to None for the bindings on both the client and the service end.
Make sure the Windows Features are enabled for Named Pipe Activation for WCF 4.5 or the Non-HTTP Activation for WCF 3.5

Can I configure a WCF service and consume a different on in the same application?

I'm trying to host on a website both the creation of a WCF service to send JSON data back to the client-side, as well as consume a different webservice used for cross application data exchange (it's a medical app, the data I need is hosted in an old ASMX webservice somewhere else)
My problem is the app is behind SSL, and basic authentication (which will go when we deploy to live), the service I'm consuming is over http and the rediculous amount of settings I need in the web.config are getting in each others way.
The web.config looks like this now
<behaviors>
<endpointBehaviors>
<behavior name="AJAXEndpoint" >
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyNamespace.Service.ACSvc">
<endpoint
behaviorConfiguration="AJAXEndpoint"
address="" binding="wsHttpBinding" bindingConfiguration="UsernameWithTransport"
contract="MyNamespace.Service.IACSvc">
</endpoint>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="wsAbbVieSoap">
<security mode="Transport" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://somewhere.else.com/externalservice.asmx"
binding="basicHttpBinding" bindingConfiguration="wsAbbVieSoap"
contract="AbbvieService.wsAbbVieSoap" name="wsAbbVieSoap" />
</client>
Over various iterations, I've had my service working, but the external service not working or neither service working.
What I want
My service - HTTPS, Basic authentication, response in JSON
External service - HTTP, Anonymous, SOAP response
These services are not aware of each other and have nothing to do with each other. They're separate parts of the same website - one (mine) for my own clientside scripts, and the other (external) for me to call serverside for various business uses.
Any help appreciated

IIS Hosted WCF Rest Service keeeps prompting for Windows Auth Credentials

I have a WCF Rest Service that I'm building. The service is hosted in IIS under an SSL. And I have the site in IIS setup to use Windows authentication with Anonymous authentication disabled.
However, when I attempt to navigate to service.svc file in the browser to test the windows authentication I am prompted from my credentials as expected. However, after entering my credentials it continuous to prompt me over and over. And I don't know why or what I'm missing.
If I re-enable Anonymous authentication and navigate to the service.svc file then the wsdl data loads..but from my understanding is no longer using windows authentication at that point.
I have tested this in IE and Firefox and both of them do the same thing.
Here is my web.config
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebHttpBindingConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="httpEnabled">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceCredentials>
<windowsAuthentication allowAnonymousLogons="False" includeWindowsGroups="True"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="myService" behaviorConfiguration="httpEnabled">
<endpoint address="" binding="webHttpBinding" contract="myContract" behaviorConfiguration="EndpBehavior" bindingConfiguration="WebHttpBindingConfig" />
</service>
</services>
Any help figuring this out would be great. If you need any other information please let me know. Thank you.
Problem: Continuous prompt for creds when attempting to view Service.svc in browser.
Expected result: Upon entering valid creds they Service.svc page should load
EDIT:
I was going to post images of the Auth Settings and an example of what it was dong to give a visual, but I don't have enough reputation yet. Sorry.
I figured it out. It ended up being a server configuration issue. I discovered I could load the Service.svc file from a remote machine with valid creds. So after I did some searching I found the following article:
http://warnajith.blogspot.com/2011/06/iis-75-401-unauthorized-access-error.html
The issue was I needed to DisableLoopbackCheck. So after I followed the steps on that page to update the registry it loaded correctly
Note: If you're on a windows 2012 server you do not need to do step 1 in the link provided.
Hope this helps someone else in the future.

Improve WCF service performance

My company owns a server with 24 cores and a lot a RAM inside. The OS is Windows 2008 R2 SP1. I deployed on this server a WCF application, hosted in IIS. On the same server I installed a multithreaded client which calls one of the WCF service, as often as possible. I encountered a bottleneck : all the cores on the server are used, but at a very low level, so the CPU consumption doesn't exceed 10 %. My WCF service is configured like this :
<system.serviceModel>
<services>
<service behaviorConfiguration="myBehavior" name="...">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="myBinding" bindingNamespace="..." contract="..."/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="200" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="myBinding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2147483647" maxReceivedMessageSize="2147483647" portSharingEnabled="false" transactionFlow="false" listenBacklog="2147483647">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
<readerQuotas maxDepth="64" maxStringContentLength="204800" maxArrayLength="204800" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</netTcpBinding>
</bindings>
My service has also the following attributes : InstanceContextMode.Single and ConcurrencyMode.Multiple. Did anyone encounter a similar problem ? I searched the solution for days, but I didn't find it yet :(
Thank you in advance !
I'm not sure how you're measuring the performance bottleneck but no matter how many client calls you generate, the service will only handle 200 calls at a time. The netTcpBinding is uses sessions so the throttle there is the maxConcurrentSessions="200" setting. You've configured the service as a multi-threaded singleton which is limited to 200 simultaneous calls by the maxConcurrentCalls="200" setting. The CPU load will also depend on how much work is performed during each call and whether it is IO bound or not. Review the serviceThrottling element documentation and try increasing both settings to see if your throughput improves.
If your sevice implementation allows, I would recommend you try configuring the service with InstanceContextMode.PerSession and ConcurrencyMode.Single to compare throughput with your current configuration. IIS 7x hosts WCF services using the Windows Process Activation Service (WAS). WAS is designed to handle concurrency. A singleton configuration negates the value of using WAS.

isOneWay WCF Services

I'm attempting to create a process that verifies data within a database and notifies users of errors. My initial thought was to create a web service that is triggered when the user saves the web form. That web service would begin the process of validating the data and populating another table with information about what information it believes is invalid. From the beginning I had intended for this web service to return instantly prior to the actual completition of the data verification. The data verification is going to be a longer process and isn't intended to be form validation. It's also okay if it were to happen to fail since the process will be refreshed every evening also so I’m not concerned about that.
OneWay services seems like the most logical choice for this. I have already written the service and everything is working great without OneWay being present. However the moment I add OneWay the process no longer works. What is particularly puzzling to me is I have a line that outputs a log file at the very beginning of the web service method and it occasionally writes the log when I call the service. Not every time, but sometimes. I also have multiple log statements that get outputted and it has never made it past the first line once isOneWay is enabled. It seems like the code is just being arbitrarily halted. Has anyone ever run into this before? My next option is to create a network queue task that receives the web service call directly and adds it to its queue and I was hoping to avoid doing that.
A bit more background information, I am new to WCF services but not web services in general. The web application is written in ASP.Net and is calling the webservice via HttpGet.
I'm open to other architecture suggestions and any input is greatly appreciated.
Here is the ServiceModel element from the web.config:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="WebHttpBinding_Service">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport authenticationScheme="Negotiate,Ntlm"/>
</binding>
</customBinding>
<webHttpBinding>
<binding name="webHttpBinding_IISAuthen">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="Namespace.Service" behaviorConfiguration="Namepsace.ServiceBehavior">
<endpoint address="" behaviorConfiguration="Namespace.ServiceAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="webHttpBinding_IISAuthen" contract="Namespace.Service" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Namespace.ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Namespace.ServiceBehavior">
<!-- 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 aspNetCompatibilityEnabled="true" />
<client>
<endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_Service"
contract="Service" name="WebHttpBinding_Service" />
</client>
</system.serviceModel>
When running into problems like these in WCF, where something stops working when changing the configuration, I would definitely start by tracing the running service. WCF has a great tracing mechanism which you start by editing the configuration. You can read all about configuring it here.
I discovered the problem. It may seem odd but the service was being run within the same project and that seemed to be causing the problem with using it as a one way service. I moved it out into its own project everything worked as expected.
I thank everyone for their time, the tracing will certainly prove to be useful in the future.

Categories