WCF Windows Authentication not working - wcf

I've created a WCF service and I'm trying to set it up to disable anonymous access. I'm getting the following error when trying to add my service reference in an application:
Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.
Below is my configuration file for my WCF service:
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows"/>
<customErrors mode="Off" />
</system.web>
<appSettings>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
What needs to change so it will use Windows authentication?
EDIT *
Jeff, here is my error message:
The request failed with the error message:
--
<html>
<head>
<title>Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span>
<H1>
Server Error in '/' Application.<hr width="100"% size="1" color="silver">
</H1>
<h2>
<i>Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.</i>
</h2>
</span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br>
<br>
<b> Exception Details: </b>System.NotSupportedException: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.<br>
<br>
<b>Source Error:</b>
<br>
<br>
<table width="100"% bgcolor="#ffffcc">
<tr>
<td>
<code>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
</code>
</td>
</tr>
</table>
<br>
<b>Stack Trace:</b>
<br>
<br>
<table width="100"% bgcolor="#ffffcc">
<tr>
<td>
<code>
<pre>
[NotSupportedException: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.]
System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateHttpSettings(String virtualPath, Boolean isMetadataListener, Boolean usingDefaultSpnList, AuthenticationSchemes& supportedSchemes, ExtendedProtectionPolicy& extendedProtectionPolicy, String& realm) +198300
System.ServiceModel.Channels.HttpChannelListener.ApplyHostedContext(String virtualPath, Boolean isMetadataListener) +104
System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener(BindingContext context) +156
System.ServiceModel.Channels.Binding.BuildChannelListener(Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters) +166
System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession) +393
System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result) +583
System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +2020
System.ServiceModel.ServiceHostBase.InitializeRuntime() +82
System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +64
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +255
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172
[ServiceActivationException: The service '/SLtoCRM.svc' cannot be activated due to an exception during compilation. The exception message is: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service..]
System.Runtime.AsyncResult.End(IAsyncResult result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178702
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107
</pre>
</code>
</td>
</tr>
</table>
<br>
<hr width="100"% size="1" color="silver">
<b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
</font>
</body>
</html>
<!--
[NotSupportedException]: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.
at System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateHttpSettings(String virtualPath, Boolean isMetadataListener, Boolean usingDefaultSpnList, AuthenticationSchemes& supportedSchemes, ExtendedProtectionPolicy& extendedProtectionPolicy, String& realm)
at System.ServiceModel.Channels.HttpChannelListener.ApplyHostedContext(String virtualPath, Boolean isMetadataListener)
at System.ServiceModel.Channels.HttpTransportBindingElement.BuildChannelListener[TChannel](BindingContext context)
at System.ServiceModel.Channels.Binding.BuildChannelListener[TChannel](Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
at System.ServiceModel.Description.DispatcherBuilder.MaybeCreateListener(Boolean actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, String listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, IChannelListener& result, Boolean supportContextSession)
at System.ServiceModel.Description.DispatcherBuilder.BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, Boolean supportContextSession, IChannelListener& result)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
[ServiceActivationException]: The service '/SLtoCRM.svc' cannot be activated due to an exception during compilation. The exception message is: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service..
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)
--><!--
This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
--.
Metadata contains a reference that cannot be resolved: 'xxxx/SLtoCRM.svc'.
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
The remote server returned an error: (401) Unauthorized.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I tried creating a new WCF service and I'm getting the same issue. Here is my updated config file in my WCF service:
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
</system.web>
<appSettings>
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="SLtoCRM">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="CRMWCF.ISLtoCRM" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="SLtoSQL">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="CRMWCF.ISLtoSQL" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CRMBehavior">
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Just for grins, here is one of my interfaces used in the endpoints:
namespace CRMWCF
{
[ServiceContract]
public interface ISLtoSQL
{
[OperationContract]
IEnumerable<Dictionary<string, string>> GetOptionSet(string connectionString, int objectTypeCode, string optionSetName);
}
}
Do I need to do anything in the config file of my application that I'm trying to add this service to?
Thanks

You need to add the Services section. This way you can give the Service endpoint, and tell it to use the bindingconfiguation you created.
<System.ServiceModel>
<services>
<service name="ServiceName" >
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="namespace.IContract" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</System.ServiceModel>

Related

Error In XamarinAndroid "System.Net.Sockets.SocketException: Connection refused at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException"

I created A WCF Application that has 3 methods to return some users Data for test. that It has no Problem I tested.
I added the Web Reference in Xamarin But When I want to use the method it has Error Exception.
WCF web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpointBehavior">
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyStoreService.MyStoreService"
behaviorConfiguration="MyBehavior">
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="MyBinding"
behaviorConfiguration="EndpointBehavior"
contract="MyStoreService.IMyStoreService"
name="MyStoreService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:58514/MyStoreService.svc" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MyBinding" >
</binding>
</wsHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="ServiceConnection" connectionString="Data Source=.;Initial Catalog=StoreDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
this is the Code I Use in Xamarin android with C#
localhost.MyStoreService service = new MyStoreService();
var user = service.UserGetById(1, true);
label.Text = user.FName;
And this is the Error Exception
{System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused at System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs:127 at System.Net.Sockets.Socket.EndConnect (System.IAsyncResult asyncResult) [0x0002c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net.Sockets/Socket.cs:1214 at System.Net.WebConnection+<>c.<Connect>b__16_1 (System.IAsyncResult asyncResult) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:182 at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) [0x00019] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs:538 --- End of stack trace from previous location where exception was thrown --- at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x00197] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:180 --- End of inner exception stack trace --- at System.Net.WebConnection.Connect (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x0025d] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:202 at System.Net.WebConnection.InitConnection (System.Net.WebOperation operation, System.Threading.CancellationToken cancellationToken) [0x000cc] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebConnection.cs:273 at System.Net.WebOperation.Run () [0x00052] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebOperation.cs:268 at System.Net.WebCompletionSource`1[T].WaitForCompletion () [0x0008e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System/System.Net/WebCompletionSource.cs:111 at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (System.String method_name, System.Object[] parameters) [0x000a7] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/System.Web.Services/System.Web.Services.Protocols/SoapHttpClientProtocol.cs:364 at MyStoreApplication.localhost.MyStoreService.UserGetById (System.Int64 UId, System.Boolean UIdSpecified) [0x00001] in F:\StoreProject\MyStoreApplication\MyStoreApplication\Web References\localhost\Reference.cs:227 at (wrapper remoting-invoke-with-check) MyStoreApplication.localhost.MyStoreService.UserGetById(long,bool) at MyStoreApplication.MainActivity.GetData () [0x00007] in F:\StoreProject\MyStoreApplication\MyStoreApplication\MainActivity.cs:147 at MyStoreApplication.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x000aa] in F:\StoreProject\MyStoreApplication\MyStoreApplication\MainActivity.cs:47 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00010] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.App.Activity.cs:2986 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.3(intptr,intptr,intptr)}
I am new to wcf and xamarin. Please help me to solve the problem?
this is the Pic may help
[1]: https://s21.picofile.com/file/8444961626/Error.png

getting MessageSecurityException while communicating with Hosted website : WCF

I am working on WCF in following scenario
"Authenticating and Authorizing Users by Using the SQL Membership Provider and the SQL Role Provider"
Host : Asp.NET website
Client : Console application.
I am using WsHttpBinding over HTTPS communications (at my local),
I am getting following exception while communicating
Unhandled Exception:
========================================================
System.ServiceModel.Security.MessageSecurityException: An u
nsecured or incorrectly secured fault was received from the other party. See the
inner FaultException for the fault code and detail. ---> System.ServiceModel.Fa
ultException: At least one security token in the message could not be validated.
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChann
el.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState
, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChann
el.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperat
ion(SecuritySessionOperation operation, EndpointAddress target, Uri via, Securit
yToken currentToken, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetToken
Core(TimeSpan timeout)
at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan tim
eout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecurit
ySessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceMod
el.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeo
ut)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeS
pan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at ProductsClient.ProductsService.IProductsService.ListProducts()
at ProductsClient.ProductsService.ProductsServiceClient.ListProducts() in D:\
Visual Studio\WCF\PracticeInNotes\51Web_HttpHost_SQLAuth_SQLAutr_TrSec\Web_HttpH
st_SQLAuth_SQLAutr_TrSec\ProductsClient\ProductsService.cs:line 285
at ProductsClient.Program.Main(String[] args) in D:\Visual Studio\WCF\Practic
eInNotes\51Web_HttpHost_SQLAuth_SQLAutr_TrSec\Web_HttpHst_SQLAuth_SQLAutr_TrSec\
ProductsClient\Program.cs:line 45
Press any key to continue . . .
Here is Web.Config of Host Web Site
===================================
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="AdventureWorksConnection" />
<connectionStrings>
<add name="AdventureWorksConnection" connectionString="Data Source=WIN764\SQL2008;Initial Catalog=AdventureWorks2008;User ID=sa;Password=123" providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="ProductsServiceWSHttpBindingConfig">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ProductsBehavior" name="ProductsService.ProductsServiceImpl">
<endpoint address="https://localhost/InternetProductsService/ProductsService.svc" binding="wsHttpBinding"
bindingConfiguration="ProductsServiceWSHttpBindingConfig" name="ProductsServiceWSHttpEndpoint"
contract="ProductsService.IProductsService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ProductsBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="AdventureWorksSqlRoleProvider" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="AdventureWorksSqlProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics wmiProviderEnabled="true">
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" >
<filters>
<clear/>
</filters>
</messageLogging>
</diagnostics>
</system.serviceModel>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<authentication mode="Forms" />
<membership defaultProvider="AdventureWorksSqlProvider">
<providers>
<clear />
<add name="AdventureWorksSqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="AdventureWorksConnection" applicationName="InternetProductsService " />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="AdventureWorksSqlRoleProvider">
<providers>
<clear />
<add name="AdventureWorksSqlRoleProvider" connectionStringName="AdventureWorksConnection" applicationName="InternetProductsService " type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
</system.web>
</configuration>
Here is App.Config of Client Application
========================================
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="ProductsClientWSHttpBindingConfig">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost/InternetProductsService/ProductsService.svc"
binding="wsHttpBinding"
bindingConfiguration="ProductsClientWSHttpBindingConfig"
contract="ProductsClient.ProductsService.IProductsService"
name="WSHttpBinding_IProductsService" />
</client>
</system.serviceModel>

RoleEnvironmentException in Microsoft Azure Instance Deployment

I'm having a game with a WCF service and Azure.
I have several WCF Services running successfully on Azure, this particular service has been operating correctly until I decided to redeploy it under a different (existing) Cloud Service.
I removed it from under the role of cloud service X in my VS solution and added it to another cloud service role. I published and when I do, I receive the exception error
"Unhandled Exception: Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironmentException". I'm told that the service is been recycled, constantly.
This message appears in the Azure management portal under the instance this WCF service is under. I've tried it on it's own cloud service and under a service with of instances.
Having reviewed scant articles on the issue (http://blogs.msdn.com/b/davidmcg/archive/2011/03/10/diagnosticmonitor-roleenvironmentexception-was-unhandled.aspx) and (http://www.microsofttranslator.com/bv.aspx?from=&to=en&a=http%3A%2F%2Fpul.se%2FBlog-Post-Error-RoleEnvironmentException-was-unhandled_Video-ptFrIOhJU6%2ClWCxfMvJiNbE)
Remoting onto the instance, I have the following in event viewer:
Application: WaIISHost.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironmentException
Stack:
at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<InitializeRole>b__0()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
I have also found:
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironmentException: error
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetLocalResource(String localResourceName)
at WCFServiceDataTransfer.AzureLocalStorageTraceListener.GetLogDirectory()
at WCFServiceDataTransfer.WebRole.OnStart()
But this is auto generated code in AzureLocalStorageTraceListener.
How can I get to the bottom of this problem?
Web.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- To collect diagnostic traces, uncomment the section below or merge with existing system.diagnostics section.
To persist the traces to storage, update the DiagnosticsConnectionString setting with your storage credentials.
To avoid performance degradation, remember to disable tracing on production deployments.
<system.diagnostics>
<sharedListeners>
<add name="AzureLocalStorage" type="WCFServiceDataTransfer.AzureLocalStorageTraceListener, WCFServiceDataTransfer"/>
</sharedListeners>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="AzureLocalStorage"/>
</listeners>
</source>
</sources>
</system.diagnostics> -->
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<client />
<services>
<service behaviorConfiguration="TransferServiceBehavior" name="WCFServiceDataTransfer.TransferService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransferService" contract="WCFServiceDataTransfer.ITransferService">
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="TransferService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="TransferServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false 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="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
</assemblyBinding>
<httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true" executionTimeout="14400" />
</runtime>
</configuration>
Entry
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// To enable the AzureLocalStorageTraceListner, uncomment relevent section in the web.config
DiagnosticMonitorConfiguration diagnosticConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagnosticConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
diagnosticConfig.Directories.DataSources.Add(AzureLocalStorageTraceListener.GetLogDirectory());
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
}
Ok, this is what resolved the issue.
I added the following to my ServiceDefinition.csdef file under the Imports closing tag. It was not present at all, once I added the below and published the instance was able to start.
Using version 1.8
<LocalResources>
<LocalStorage name="WCFServiceDataTransfer.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />
</LocalResources>
Help this helps someone else one day.

Registered base address schemes are [https] error

I am trying to publish a wcf web service on an iis server and have it use Windows Authentication. I'm getting an error when I even try to publish it so I haven't gotten far enough to get prompted for a username. I do have a SSL certificate and want to use ssl.
This is my error:
[InvalidOperationException: Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [https].]
System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses) +16604769
System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress) +1082
System.ServiceModel.ServiceHostBase.ApplyConfiguration() +156
System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +215
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +475
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +43
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +530
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1413
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +50
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172
[ServiceActivationException: The service '/subservice/ISubService.svc' cannot be activated due to an exception during compilation. The exception message is: Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [https]..]
System.Runtime.AsyncResult.End(IAsyncResult result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178638
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136
I've researched this a hundred times but I have very little experience with publishing a service. I've worked with them once they are built just never published one.
This is my web.config that I've modified from another web.config where that publishes fine:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpointBinding">
<security mode="Transport">
<!-- Basic <security mode="Transport"> -->
<!-- To use Basic auth, just comment Windows and use this, but you need to configure basic in IIS as well -->
<!-- <transport clientCredentialType="Basic" /> -->
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="default">
<security mode="Transport">
<!-- Basic <security mode="Transport"> -->
<!-- To use Basic auth, just comment Windows and use this -->
<!-- <transport clientCredentialType="Basic" /> -->
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata 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>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="subservice.ISubService">
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" contract="subservice.ISubService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="rest" binding="webHttpsBinding" bindingConfiguration="default" behaviorConfiguration="restBehavior" contract="subservice.ISubService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress = "https://[site]/subservice/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Anyone see what I'm doing wrong?
Instead of using basicHttpBinding, use the basicHttpsBinding
http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpsbinding.aspx

service is giving an error ServiceHost only supports class service types

I am trying to publish a service and have it use Windows Authentication and I'm getting an error when I even try to publish it so I haven't gotten far enough to get prompted for a username.
This is my error:
[ArgumentException: ServiceHost only supports class service types.]
System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) +16602430
System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts) +80
System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +174
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +475
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +43
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +530
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1413
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +50
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1172
[ServiceActivationException: The service '/subservice/ISubService.svc' cannot be activated due to an exception during compilation. The exception message is: ServiceHost only supports class service types..]
System.Runtime.AsyncResult.End(IAsyncResult result) +901424
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +178638
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136
I've researched this a hundred times but I have very little experience with publishing a service. I've worked with them once they are built just never published one.
This is my web.config that I've modified from another web.config where that publishes fine:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
<system.web>
<compilation targetFramework="4.0" debug="true">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="DefaultCache" duration="60" varyByParam="none" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpointBinding">
<security mode="None">
<!-- Basic <security mode="Transport"> -->
<!-- To use Basic auth, just comment Windows and use this, but you need to configure basic in IIS as well -->
<!-- <transport clientCredentialType="Basic" /> -->
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="default">
<security mode="None">
<!-- Basic <security mode="Transport"> -->
<!-- To use Basic auth, just comment Windows and use this -->
<!-- <transport clientCredentialType="Basic" /> -->
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="subservice.ISubService">
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" contract="subservice.ISubService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="rest" binding="webHttpBinding" bindingConfiguration="default" behaviorConfiguration="restBehavior" contract="subservice.ISubService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="p3p" value="CP="CAO PSA OUR"" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
I have nothing in my web.release.config:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
This is what my application looks like:
Anyone see what I'm doing wrong?
The error says you are using the Interface type to construct a host instead of a class type that implements your service interface ISubService.
eg.
ServiceHost host = new ServiceHost(
typeof(subservice.ISubService), new Uri("someuri"));
If this is your usage, change it to use the implemented service class type of ISubService
ServiceHost host = new ServiceHost(
typeof(subservice.SubService), new Uri("someuri"));
If configuring the service in .svc then:
<%#ServiceHost Service="subservice.SubService"%>
Also in you config file, change service name to the service instead of the service contract as:
<services>
<service name="subservice.SubService">
...