Security settings for this service require Windows Authentication - asp.net-mvc

I have an ASP.NET MVC site that contains a WCF SVC that is hosted on load balanced intranet site (2 servers). It is my understanding that for security reasons, our web server team does not allow anonymous authentication to our intranet web applications and the default is to use Windows authentication. I can access the SVC just fine on localhost, but when trying to access on the server I get the following error message:
System.NotSupportedException: Security
settings for this service require
Windows Authentication but it is not
enabled for the IIS application that
hosts this service.
I've found similar questions here on StackOverflow and the answers given didn't solve my specific issues. Here is my current web.config for the service areas...
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<client />
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_IClarityIntegration">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ClarityIntegrationBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ClarityIntegrationBehavior"
name="ClarityIntegration.MVC.Web.Services.ClarityIntegration">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_IClarityIntegration"
contract="ClarityIntegration.MVC.Web.Services.IClarityIntegration">
</endpoint>
</service>
</services>
</system.serviceModel>

This issue was actually being caused by an exception within the WCF service itself. Not sure why it ended up responding this way, but after finding the exception and fixing it, this problem went away.

Related

WCF WebService Error

Error
Error: Cannot obtain Metadata from
localhost:81/WebServices/Legacy.svc If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address. For help enabling metadata publishing, please refer to the
MSDN documentation at
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: localhost:81/WebServices/Legacy.svc Metadata
contains a reference that cannot be resolved:
'localhost:81/WebServices/Legacy.svc'.
My Web.Config
<system.serviceModel>
<services>
<service name="Web.WebServices.Legacy" behaviorConfiguration="serviceBehaviorsZero">
<endpoint address=""
name="SspService"
binding="basicHttpBinding"
bindingConfiguration="basicHttpBindingZero"
contract="Web.WebServices.ILegacy" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingZero">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehaviorsZero">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Why I not able to access my webservices using WCF Test Client?
When I acess via URL localhost:81/WebServices/Legacy.svc in browser
I get this error
The filename, directory name, or volume label syntax is incorrect.
Update: My .svc file code
<%# ServiceHost Language="C#" Debug="true" Service="Web.WebServices.Legacy" CodeBehind="Legacy.svc.cs" %>
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Legacy : ILegacy
{
public string DoWork()
{
return "https";
}
}
Put just simple file on the web site directory (hello.html), and check if it is reachable (helloworld.html)
Hello World
Hello World!!!
If not working - check your binding settings on IIS, and whether the service and it's application pool is on.
On IIS configuration, choose 'features view', and go to 'directory browsing' + enable.
At the end of the svc put : ...svc?wsdl
First check on your own local environment. After everything fine, you can check from the web.
On Visual Studio, you shall do the basic by creating new web site (new folder), and copy result to the web site (including web.config) - there is a default source code. you can add new function to service (i.e helloworld, which returns a string, and refer it on iservices).
If svc file is not created (old VS versions) - you can create text file of your own, and do some copy+paste to fix the svc file ... on web site, there shall be app_code and app_data folders.
Hope that help.
Good luck!!!

IIS Express Enable External Request - 503

I have attempted to get IIS Express working so that external users can view my MVC ASP.NET development website. I followed instructions on this SO answer but am now getting a 503 error when accessing the website using my external IP address, localhost still works fine.
My configuration file seems ok
<site name="ManagerUI" id="5">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="D:\Application Development\Manager\MAIN-Branch\ManagerUI\ManagerUI" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:1904:" />
</bindings>
</site>
I found the following SO answer which solves the issue, but it will ONLY allow it to work on an external address rather than all my IP addresses (localhost, external one etc)
<binding protocol="http" bindingInformation=":1904:your-machine-name" />
I managed to solve it, my mistake was thinking that you could only have one binding set, I then setup binding for every external address I wished to serve on and it now all works
<bindings>
<binding protocol="http" bindingInformation=":1904:" />
<binding protocol="http" bindingInformation=":1904:machineName" />
<binding protocol="http" bindingInformation=":1904:10.1.10.123" />
</bindings>

Could not connect to net.tcp://localhost... TCP error code 10061

Referring to a video tutorial about WCF service in windows service,i have created a sample WCF service and hosted that Service with netTcpBinding in Windows Service.(since i want this WCF service to run as windows service)
Its a simple service which adds/deletes/loads employee details, and is consumed by a windows forms application.that worked fine,when i build the whole solution(consisting wcf service + windows service + client app), however when i wanted to verify that my client isn't directly referring to the project in the solution, so i excluded both the services(wcf+windows) from my solution. it stopped working throwing an error, reading:
Could not connect to net.tcp://localhost:8010/EmployeeService.Service1/. The connection attempt lasted for a time span of 00:00:02.0180000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8010.
Important point that might help to answer:
WCF service and windows service have identical app.config
Windows service is running as a service
this is my client app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8010/EmployeeService.Service1/"
binding="netTcpBinding" bindingConfiguration="netTcpEndPoint"
contract="Service1.IService1" name="netTcpEndPoint">
<identity>
<userPrincipalName value="user#company.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
any help would be greatly appreciated....
Found the answer myself, hope it helps other looking for it...
I found that event of worker_DoWork() is not triggered, so add worker.RunWorkerAsync(); as shown in the code below to your windows service
protected override void OnStart(string[] args)
{
worker = new BackgroundWorker();
worker.RunWorkerAsync();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
}
Delete the Service reference from client project, add it again, since it makes changes to your app.config file.
Just a quickie note that may help some folk:
This error came up between two computers that controlled a Perkin Elmer - Thermo Fisher Scientific Liquid Handling apparatus (robot).
McAfee Antivirus was interfering with their communication and uninstalling McAfee banished the error.
MS Security Essentials Antivirus did NOT interfere.

WCF help, how can I expose a service over http, that calls another service over net.tcp?

I have a WCF .svc file hosted in IIS. I want to use basicHTTP binding. This services job is to actually call another service over net.tcp. Everything works fine locally, but when I deployed, I'm getting this error.
The provided URI scheme 'http' is
invalid; expected 'net.tcp'. Parameter
name: via
Here is the server config
<client>
<endpoint address="net.tcp://localhost:9300/InternalInterfaceService"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IInternalInterfaceService"
contract="IInternalInterfaceService" name="NetTcpBinding_IInternalInterfaceService">
<identity>
<servicePrincipalName value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="MyExternalService">
<endpoint address="" binding="basicHttpBinding" contract="IMyExternalService" />
</service>
</services>
And here is the config that svcutil generates
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyExternalService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myserver.somesdomain.com/Services/MyExternalService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyExternalService"
contract="IMyInternalService" name="BasicHttpBinding_IMyExternalService" />
</client>
</system.serviceModel>
What do I need to do to wire this up correctly. I do not want to expose InternalInterfaceService over http. What am I doing incorrectly here? Any tips or suggestions are certainly appreciated.
Thanks,
~ck
You need a routing service - one that exposes a HTTP endpoint to the world, and uses netTcp internally.
Basically, your outward facing http service must become a client in turn to call the internal netTcp service.
You can definitely do this in .NET 3.5 with a bit of effort:
Service Station: Building a WCF Router, Part 1
Service Station: Building a WCF Router, Part 2
or you can use the new WCF 4 Routing Service in .NET 4 / VS 2010:
Creating Routing Service using WCF 4.0, .NET Framework 4.0 and Visual Studio 2010
WCF in .NET 4 the WCF Routing service

Unable to host WCF service correctly in IIS7

I have a WCF Service library written in .NET 4.0. I have a WCF application (in order to host this service in IIS) within the same solution. It contains the WCF library assembly reference and a service.svc file pointing to the service from the library along with a web.config that is a replica of the WCF service library's app.config. The WCF application is set to host the service in IIS7 (the virtual directory has been set). The same solution contains an ASP.NET Webforms solution to which I have added a service reference pointing to the WCF service I hosted in IIS (as mentioned).
When i start an instance of this ASP.NET Web application, I get a message saying that "The WCF service has been hosted" and the ASP.NET application can access the data from it correctly. However, when i try and access this data via a service reference added to an MVC 2 Web Application on the same machine in a different solution (pointing to the service hosted in IIS), I get a "The remote server returned an error: (405) Method Not Allowed." protocol exception . However, the MVC application is able to access the service data if I manually invoke an instance of the WCF Application that I was using to host the WCF Service Library from the other solution.
I am using VS2010 Beta 2 as my development IDE. I have been stuck with this issue for a while now. Any help would be appreciated.
My service config is as follows:-
<system.serviceModel>
<services>
<service behaviorConfiguration="CruxServices.BasicSearchServiceBehavior"
name="CruxServices.BasicSearch.BasicSearch">
<endpoint address="" binding="wsHttpBinding" name="WSBindingEndpoint" bindingConfiguration="WSBindingConfig"
contract="CruxServices.BasicSearch.Interfaces.IPropertyListFilter">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" name="MexEndpoint"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/CruxServices" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CruxServices.BasicSearchServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSBindingConfig">
<security mode="None">
<transport clientCredentialType="None"/>
<message establishSecurityContext="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
In the configuration of IIS you specify which version of the .net framework you want to use.
In this context there are 4 versions of the .net framework: 1.0, 1.1, 2.0 and 4.0
Your first problem is that IIS is not configured to run framework 4.0
You may however you may have a bigger problem, I am not sure if it is possible, you may need IIS 7.5
EDIT
Have now checked it. It will work, the only thing you need to do is to make sure that framework 4 is selected as the framework for the application pool.

Resources