WCF Services - Configuration web service binding exception - asp.net

All,
Env:
Asp.net 4.0
IIS 7 (or greater)
WCF service consumed by SL component
Authentication:
Anonymous/Forms
When I attempt to browse to my WCF web service (using browser) I get the following exception on my web service, I need to get rid of this error:
The authentication schemes configured on the host ('IntegratedWindowsAuthentication') do not allow those configured on the binding 'BasicHttpBinding' ('Anonymous'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.
I looked at ALL related posts and none of them help me.
I am not using any authentication or user/pwd transmission for my service.
The service I need to get working is consumed by Silverlight component and has this name in web.config file:
Htmls.WebStore.Services.WebStoreServices (ignore the other service).
Here's my web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebStoreServices_InsecureTransport" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="4096" />
<security mode="None" />
</binding>
<binding name="basicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SitefinityWebApp.Sitefinity.Services.Content.EventsAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="EndpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="Telerik.Sitefinity.Web.Services.LocalizationBehavior" />
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Htmls.WebStore.Services.WebStoreServices">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WebStoreServices_InsecureTransport" contract="Htmls.WebStore.Services.IWebStoreServices" />
</service>
<service name="SitefinityWebApp.Sitefinity.Services.Content.Events">
<endpoint address="" behaviorConfiguration="SitefinityWebApp.Sitefinity.Services.Content.EventsAspNetAjaxBehavior" binding="webHttpBinding" contract="SitefinityWebApp.Sitefinity.Services.Content.Events" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

The exception was caused by having incorrect permission on the folder where the xxxxx.svc file was. The folder was locked down using security permissions.

Related

WCF service call returns empty file / page

The problem:
When I'm calling my deployed WCF service, the browser downloads an empty svc file and does not show me the page with the service xml file.
The context:
I have to move the webapp hosting the WCF service to a new server. This service was working fine on the old server, that was running IIS.
The new server has 2 webservers running. IIS 8.5 and WAMP 2.5, because the server hosts an Php app and Jira.
The setup:
The WAMP server listens to the 80 port and then redirects to IIS, to a specific port, if needed. This is an example for the setup.
Wamp config (https-vhosts.confg):
<VirtualHost *:80>
ServerName site.de
ServerAlias www.site.de
<Proxy *>
Require all granted
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:9050/
ProxyPassReverse / http://localhost:9050/
The service URL:
https://www.site.de/folder/service.svc
Service config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="someBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="52428899">
<readerQuotas maxDepth="64" maxStringContentLength="81920" maxArrayLength="163840" maxBytesPerRead="40960" maxNameTableCharCount="163840" />
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="LargeServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<useRequestHeadersForMetadataAddress />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
<endpoint address="http://www.site.de/folder/service.svc"
binding="basicHttpBinding"
bindingConfiguration="someBinding"
contract="ExampleServiceModels.IExampleService" />
</service>
</services>
I have never worked with wamp before. And I don't have much experience with WCF settings also. Any ideas or tips would be highly appreciated.
EDIT
Using the wcf test client i get this:
Error: Cannot obtain Metadata from http://www.site.de/folder/ExampleService.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: http://www.site.de/folder/ExampleService.svc Metadata contains a reference that cannot be resolved: 'http://www.site.de/folder/ExampleService.svc'. The requested service, 'http://www.site.de/folder/ExampleService.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://www.site.de/folder/ExampleService.svc The document at the url http://www.site.de/folder/ExampleService.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:- Report from 'XML Schema' is 'Root element is missing.'.- Report from 'DISCO Document' is 'Root element is missing.'.- Report from 'WSDL Document' is 'There is an error in XML document (0, 0).'. - Root element is missing.
You need to specify a MEX (meta data exchange) binding to expose you WSDL. Example (look at the address "mex"):
<service name="ExampleServices.ExampleService" behaviorConfiguration="LargeServiceBehavior">
<endpoint address="http://www.site.de/folder/service.svc" binding="basicHttpBinding"
bindingConfiguration="someBinding"
contract="ExampleServiceModels.IExampleService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
To get the wsdl type in the browser:
https://www.site.de/folder/service.svc?wsdl
Not sure this answer will help OP after almost 3 years. But it is more intended for #GothamLlianen. But if you want to access a WFC service on a HTTPS connection, you need to specify that binding explicitly.
Add this in the <system.serviceModel> node of the Web.Config
<bindings>
<webHttpBinding>
<binding name="HttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
Then add the name, in this case "HttpsBinding" to the endpoint
<endpoint bindingConfiguration="HttpsBinding"
The complete node below for reference
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="MyProject.Api">
<endpoint bindingConfiguration="HttpsBinding" address="" behaviorConfiguration="web" binding="webHttpBinding" contract="MyProject.IApi" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="HttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

Why doesn't my serviceAuthenticationManagerType get called for basic authentication?

I am working with WCF OData Services and trying to use basic authentication. When I browse to my OData Services in a web browser I get the username/password prompt. But when I enter a user name and password my custom serviceAuthenticationManagerType does not get called and the login fails. Do I have something configured wrong?
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="basicHttp">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="dataServiceBehavior">
<!-- 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="true" />
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="WcfResearch.AuthorizationManagers.WcfResearchAuthorizationPolicy, WcfResearch.AuthorizationManagers" />
</authorizationPolicies>
</serviceAuthorization>
<serviceAuthenticationManager authenticationSchemes="Basic" serviceAuthenticationManagerType="WcfResearch.AuthorizationManagers.WcfResearchAuthenticationManager, WcfResearch.AuthorizationManagers"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="WcfResearch.WcfDataService1" behaviorConfiguration="dataServiceBehavior">
<endpoint binding="webHttpBinding" bindingConfiguration="basicHttp" contract="System.Data.Services.IRequestHandler" />
</service>
</services>

WCF Endpoint Configuration Issue

I'm getting the following error when my ASP.NET 4.0 site loads, and it's because of my WCF service settings in the web.config file (I'm just not enough of a WCF expert and Google isn't helping :)):
The endpoint at '[Path to my Service.svc]' does not have a Binding
with the None MessageVersion.
'System.ServiceModel.Description.WebScriptEnablingBehavior' is only
intended for use with WebHttpBinding or similar bindings.
I was using webHttpBinding but was getting the following error, so now I'm using basicHttpBinding after following the advice of this post:
Security settings for this service require 'Anonymous' Authentication
but it is not enabled for the IIS application that hosts this
service.
Anyways, here's the relevant info from my web.config. Please help!
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ABC.ProjectName.Web.ServiceBehavior">
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ABC.ProjectNameDell.Web.ServiceBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"
aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="webHttpBinding_AnonymousDisabled" >
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="ABC.ProjectName.Web.AjaxService" >
<endpoint address="/"
behaviorConfiguration="ABC.ProjectName.Web.ServiceBehavior"
binding="basicHttpBinding"
contract="ABC.ProjectName.Web.AjaxService" />
</service>
</services>
</system.serviceModel>
You can't use basicHttpBinding with enableWebScript. Set your binding to WebHttpBinding.
<service name="ABC.ProjectName.Web.AjaxService" >
<endpoint address="/" behaviorConfiguration="ABC.ProjectName.Web.ServiceBehavior"
binding="webHttpBinding"
contract="ABC.ProjectName.Web.AjaxService" />
</service>

Unable to Connect to WCF Service from MVC Site

I've written a WCF service that is hosted within a Windows Service on my home computer. I then wrote an MVC3 site that is attempting to connect to the service. The MVC3 site is hosted on godaddy servers. I opened the ports on my firewall correctly because I am able to access the service description site from a computer on a different network, and I even had a friend connect to the web service from a console app running on his computer, and it worked perfectly. However, when I attempt to call the web service from my MVC3 site it throws the following error:
There was no endpoint listening at http://myExternIpAddress:8000/MyService/service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Here is the important part of the app.config for the service:
<services>
<service name="MyService.MyService"
behaviorConfiguration="MyServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService/service" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="MyService.IMyService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
and here is the service section of the web.config for the MVC3 site
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myExternalIpAddress:8000/MyService/service"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
contract="LocalService.IMyService" name="BasicHttpBinding_IMyService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thanks for any help that you can provide!
I would contact GoDaddy for support. If the WCF service works from your friends machine - it is likely a hosting environment issue.

Set up wcf service for http and https and also add username/password to its access

I am kinda new to WCF and the setting up of service and have 2 questions. My first question I have a service that will be accessed via https on a web server. However locally on my local IIS7, it will be accessed via http as https is not available. How can I set up a service to be accessed by both?
My second question is regarding how I can set up a service that requires a username and password to be accessed. The service that I have in place I dont want methods within it to be accessed unless the calling application has the rights to do so?
Here is an example of the relevant area of my web.config file.
<system.serviceModel>
<bindings>
<webHttpBinding>
<!-- standard AJAX binding that supports SSL -->
<binding name="TransportSecurity">
<security mode="Transport" />
</binding>
<!-- standard AJAX binding for HTTP only -->
<binding name="NoSecurity">
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="ServiceBehavior" name="ServiceName">
<endpoint address=""
behaviorConfiguration="EndPointBehavior"
binding="webHttpBinding"
bindingConfiguration="NoSecurity"
contract="App.Service.ServiceName" />
</service>
</services>
<diagnostics>
<messageLogging logMessagesAtTransportLevel="true" logMessagesAtServiceLevel="false" logMalformedMessages="true" logEntireMessage="false" maxSizeOfMessageToLog="65535000" maxMessagesToLog="500" />
</diagnostics>
</system.serviceModel>
In this config, the service is set up for http only and not username/password applied to it.
You can add the username password configuration to your bindings:
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
and
<security mode="TransportCredentialOnly"> <!-- This means http + credential -->
<transport clientCredentialType="Basic" />
</security>
As for authorization, there are a bunch of options. The very simplest is to apply a custom username password validator (artibtrary example taken from Link):
<serviceBehaviors>
<behavior name="CustomValidator">
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType=
</behavior>
</serviceBehaviors>
At a more sophisticated level, read up on the ServiceAuthorizationManager:
http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceauthorizationmanager.aspx

Resources