Enabling HTTPS over a WCF Service on IIS - wcf

Asking this question again in stack overflow seems stupid as there are enough posts already on this topic...but i can see that every post has its own way of achieving this..So my config file is specified here below...I have followed up all the relevant posts and wrote this Web config file..But after all efforts also i get this error below :
"Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]."
Here is my Web.config file
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<globalization requestEncoding="utf-8" uiCulture="en" culture="en-US" responseEncoding="utf-8"/>
</system.web>
<system.serviceModel>
<services>
<service name="WcfService.Service1" behaviorConfiguration="ReqServiceBehaviour">
<endpoint address ="" binding="webHttpBinding" contract="WcfService.IService1" behaviorConfiguration="web"/>
<endpoint address="files" behaviorConfiguration="web" binding="webHttpBinding"
bindingConfiguration="httpStreamingBinding" name="UploadEndpoint"
contract="WcfService.IService1" />
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="WcfService.IService1"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="httpStreamingBinding" transferMode="Streamed" />
</webHttpBinding>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ReqServiceBehaviour">
<!-- To avoid disclosing metadata information, set the values 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment 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>
</configuration>

May be you can try following
In order to use https, you require to set httpsGetEnabled="true" instead of httpGetEnabled="true"

Related

System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at configured url

My wcf service was working until I made two changes. When I run it in debug mode I get no errors but when I deploy it to production I get the "No End Point" exception. I've followed the advise given in other posts but no change. Can anyone help me sort this out?
1. Added a method that accepts a string and a byte array
Function method3(ByVal parameter1 As String, ByVal parameter2 As Byte()) As String
2. Added a section to the web.config so larger messages could be sent
<bindings>
<basicHttpsBinding>
<binding maxReceivedMessageSize="2100000000"></binding>
</basicHttpsBinding>
</bindings>
WCF Service Configuration
<system.serviceModel>
<bindings>
<!--This needs to be changed to http if debugging and https for production-->
<!--<basicHttpBinding>
<binding maxReceivedMessageSize="2100000000"></binding>
</basicHttpBinding>-->
<basicHttpsBinding>
<binding maxReceivedMessageSize="2100000000"></binding>
</basicHttpsBinding>
</bindings>
<services>
<service name="penergydata.penergydata">
<host>
<baseAddresses>
<!--This needs to be changed to http if debugging and https for production-->
<!--<add baseAddress="http://localhost:49427/"/>-->
<add baseAddress="https://wcfservices.myefaactweb.com/penergydata/"></add>
</baseAddresses>
</host>
<!--This needs to be changed to http if debugging and https for production-->
<!--<endpoint address="" binding="basicHttpBinding" contract="penergydata.Ipenergydata"/>-->
<endpoint address="" binding="basicHttpsBinding" contract="penergydata.Ipenergydata"/>
</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>
<!--This needs to be changed to http if debugging and https for production-->
<!--<add binding="basicHttpBinding" scheme="http"/>-->
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
Client Configuration
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpsBinding_Ipenergydata">
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://wcfservices.myefaactweb.com/penergydata/penergydata.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_Ipenergydata" contract="penergydata.Ipenergydata" name="BasicHttpsBinding_Ipenergydata"/>
</client>
</system.serviceModel>
Make sure you change your binding type in your client. The client and service bindings have to match. You can always use svcutil to get the correct config info for a service as well.
<system.serviceModel>
<bindings>
<basicHttpsBinding>
<binding name="BasicHttpsBinding_Ipenergydata">
<security mode="Transport"/>
</binding>
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="https://wcfservices.myefaactweb.com/penergydata/penergydata.svc" binding="basicHttpsBinding" bindingConfiguration="BasicHttpsBinding_Ipenergydata" contract="penergydata.Ipenergydata" name="BasicHttpsBinding_Ipenergydata"/>
</client>
</system.serviceModel>

Add WCF RESTful service as application to classic ASP website

Well. We have a legacy classic asp website running on IIS 8.5 on windows server 2012. Both http and https protocols are enabled for the website. Recently I developed a standalone WCF web service and added it as Application to our website (with different application pool).
Now WCF works fine with http protocol but not with https. Service.svc loads normally with https, but for all requests returns 400
this is my web.config
<system.web>
<compilation targetFramework="4.5" />
<customErrors mode="Off"/>
<httpRuntime targetFramework="4.5" maxUrlLength="1000"/>
</system.web>
<system.serviceModel>
<services>
<service name="KATProductFilter.Service1" behaviorConfiguration="mycorp.Callback.SecPayServiceBehavior">
<endpoint address=""
binding="wsHttpBinding" bindingConfiguration="TransportBinding"
contract="KATProductFilter.IService1"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mycorp.Callback.SecPayServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="TransportBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<baseAddressPrefixFilters>
<add prefix="https://www.knivesandtools.nl/filterssl"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
Thanks in advance
I solved it. Endpoint's binding must be webHttpBinding and it MUST have both bindingConfiguration and behaviorConfiguration as follow.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="test">
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="katproductfilter_behavior">
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483646"/>
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="KATProductFilter.Service1" behaviorConfiguration="test">
<endpoint address="" binding="webHttpBinding" contract="KATProductFilter.IService1" bindingConfiguration="TransportSecurity" behaviorConfiguration="katproductfilter_behavior"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0"/>
P.S Ricardo thanks for link.

WCF Service multiple endpoint configurations not working

As per microsoft suggest, for soap1.1, soap1.2, rest based i.e. json, xml, it can be configure from web config. So the web config will decide service based on address. But not working properly. Please suggest.
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="PaymentService.Service1">
<endpoint address="soapbasic" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" behaviorConfiguration="SampleServiceBehavior" contract="PaymentService.IService1" />
<endpoint address="json" binding="webHttpBinding" bindingConfiguration="webHttpBindingJson" behaviorConfiguration="jsonBehavior" contract="PaymentService.IService1"/>
<endpoint address="xml" binding="webHttpBinding" bindingConfiguration="webHttpBindingXml" behaviorConfiguration="poxBehavior" contract="PaymentService.IService1"/>
<endpoint address="soapWs" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="PaymentService.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SampleServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceCredentials useIdentityConfiguration="false" />
</behavior>
<behavior name="SampleServiceBehaviorSOAP">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript/>
</behavior>
<behavior name="poxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding">
<security mode="None" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webHttpBindingJson">
<security mode="None"/>
</binding>
<binding name="webHttpBindingXml">
<security mode="None"/>
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding">
<security mode="None"/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
By adding behaviorConfiguration="SampleServiceBehavior" in service i.e. < service name="PaymentService.Service1" behaviorConfiguration="SampleServiceBehavior"> has solved problem. Thank u khlr for this answer.
As you've configured multiple endpoints I think you'll have to define a <baseAddress>-node.
Did you already try to get that service working with only one endpoint configured (ideally basicHttpBinding)? This way you can try step by step enhancing your service with other endpoints.
Another good idea would be to add a svclog into a <system.diagnostics>-node which could provide additional error details. Have a look at this: http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx
Edit
Error was caused by a mistake in the configuration. Solution was putting the behaviorConfiguration-attribute into the right place.
After doing this i faced another issue with rest and soap both. It was multiple end point found in service. For solving this name should be added in end point ex < endpoint name="wsSoap" address="soapWs" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="PaymentService.IService1"/>.
I added another answer for if user face this kind of issue if their multiple end point successfully worked.

Error 500.19 local IIS

I have a wcf service.
It use local IIS server.
My web.config is :
<?xml version="1.0"?>
<configuration>
<system.web>
<authentication mode="Windows"/>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="InstantMessagingBinding" closeTimeout="00:00:45">
<textMessageEncoding>
<readerQuotas maxStringContentLength="200000" maxArrayLength="200000" />
</textMessageEncoding>
<httpTransport keepAliveEnabled="false" maxReceivedMessageSize="200000" authenticationScheme="Ntlm"/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="InstantMessagingBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="Isima.InstantMessaging.WcfService.ContactService" behaviorConfiguration="InstantMessagingBehavior">
<endpoint address=""
binding="customBinding" bindingConfiguration="InstantMessagingBinding"
contract="Isima.InstantMessaging.WcfService.IContactService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And when I run my service, I get an error
This error is about "This problem can occur when the specified part of the IIS configuration file is locked at a higher level configuration."
Why this error?
Check, if all application development components are installed for IIS. e.g. .NET and ASP.NET. See the add/remove windows-feature dialog in the control panel and check the installed IIS components.
I always install all development components (ASP.NET, ...).

Simplified Configuration wsHttpBinding

I'm having a simple WCF service, deployed to IIS. I used simplified configuration with BasicHttpBinding, which worked fine.
Now I wanted to add Username/Password authentication and used wsHttpBinding. In the document above it is stated:
In .NET Framework 4, the element is optional. When a service
does not define any endpoints, an endpoint for each base address and
contract implemented are added to the service. The base address is
appended to the contract name to determine the endpoint and the
binding is determined by the address scheme.
What does this mean, how am I supposed to configure the wsHttpBinding binding by address scheme?
My config looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding>
<security mode="Message">
<transport clientCredentialType="None"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SampleWebservice.CustomValidator,SampleWebservice" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
This is Windows Server 2008, IIS 7.
It seems, the service is not picking up the wsBinding settings, as I can always see a BasicHttpBinding in the downloaded svc-file. Am I missing something?
EDIT
I applied the changes suggested by user stevedocious to alter my web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="SampleWebservice.SampleWebservice.Sample" behaviorConfiguration="customServiceBehaviour">
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<endpoint contract="SampleWebservice.SampleWebservice.ISample" binding="wsHttpBinding" bindingConfiguration="bindingConfiguration" address="" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="bindingConfiguration">
<security mode="Message">
<transport clientCredentialType="None"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="customServiceBehaviour">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SampleWebservice.CustomValidator,SampleWebservice" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
However, the metadata can't be exposed. Checking the service with the browser states, that my metadata publishing is currently disabled.
You will need to create an endpoint if you want to use anything other than the basicHttpBinding with the http/https address scheme.
In your binding definition add a name attribute
< binding name="myWSBinding" ... >
then add a bindingConfiguration and binding parameter to your endpoint definition
< endpoint binding="wsHttpBinding" bindingCongifuration="myWSBinding" ... >