Web.config for HTTP and HTTPS - asp.net

I am struggling to setup my web.config for my .NET web-service. It is supposed to accept both HTTP and HTTPS requests (HTTP only for legacy version of the client software).
I am not a web-developer so all of this is pretty much new for me.
This is the web-config that I had so far, which worked fine for HTTP only. But now I need to add HTTPS support for it.
<?xml version="1.0"?>
<configuration>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Any help is highly appreciated as I don't even know where to start.
I tried changing the serviceMetadata to
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
but that just left me with neither HTTP nor HTTPS working

Related

How to serve compiled web service on IIS?

I was given just a folder with an .asmx and previously compiled /bin folder with DLLs. I'm trying to run this web service on my local machine but I'm getting an error.
So far I did the following:
Installed IIS
Created an application 'myWebService' under 'default web site' in IIS
Pointed to the c:\inetpub\wwwroot\myWebService
when I browse to http://localhost/myWebService
HTTP Error 404.3 - Not Found The page you are requesting cannot be
served because of the extension configuration. If the page is a
script, add a handler. If the file should be downloaded, add a MIME
map
As far as I know, the 404.3 error means there is no handler which could handle the asmx file when the request comes to the IIS.
I suggest you could firstly check you have the webservicehanlderfactory in your application's handler mapping.
If there is no such handler mapping, I suggest you could try below solution to install it.
For the server:
Go to Server Manager > Add roles and features Select your server from the server pool Go to Features > WCF Services I selected all categories then installed
For the Windows10:
Open the control panel > Windows features > Select the IIS >World wide web service and enable below settings:
Besides, if you want to host the asmx on the IIS, you should also have the right web.config file.
I suggest you could ask the provider to get the config file. If you don't get it, you couldn't run the web service well.
Web.config example:
<?xml version="1.0"?>
<configuration>
<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>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<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>
</configuration>

Restful WCF can't reach operationcontract

I created a RESFTful WCF web service and i installed it in IIS as a new web application. The WCF has some actions like: Login, getEmployees ...etc. and it works fine when i publish and run it from vs, so i can reach from browser links like:
http://myserver/service.svc
http://myserver/service.svc?wsdl
http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada
and with the action links i get the exact needed data as a response.
however it works only when i run the web service from vs, but when i try to reach the links from browser and the web service is NOT running in VS i can reach only links like:
http://myserver/service.svc
http://myserver/service.svc?wsdl
but not the operational links like:
http://myserver/Login?user=sample&password=paswd
http://myserver/getEmployees?name=dada
Endpoints configurations:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings/>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="AXPAYROLL.PayrollActions" behaviorConfiguration="serviceBehavior">
<endpoint address="http://myserver/" behaviorConfiguration="RESTFriendly" binding="webHttpBinding" contract="AXPAYROLL.IPayrollActions">
<identity>
<dns value="myserver" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://myserver/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RESTFriendly">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<!-- 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 serviceAuthorizationManagerType="AXPAYROLL.DataContractLayer.DistributorValidator, AXPAYROLL" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I also created a console host application where everything worked just fine like from vs, so the problem in IIS for sure may be in permissions...
I am new in WCF but i believe that it can't be the right way to run vs always to get the wcf deployed!!! i also want to install the wcf on a productive server where no vs is installed, i know that the self hosting could be achieved with the console application but this is again not what i want, i want it torun over normal iis,any idea what is the problem? did i miss something?
When the WCF service on IIS, any base address specified in the <baseAddresses> will be ignored and the base address will be the URL to the .svc file.
The address attribute in the endpoint element is a relative address and could be like address="rest".
So in IIS, the url will be http://myserver/service.svc/rest/getEmployees?name=dada
Update:
To remove svc extension, have a look at this question

Unable to Add Assembly reference in WCF Service Application in IIS 7.5

I've been trying to add a reference to an assembly named CAPI_PInvoke.dll (64 bit) in my wcf application. The dll is placed in my bin folder but when i access my service through https://localhost:port It gives following error
The IIS has permission to read/execute contents of the entire project directroy.
here's my web.config file
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding
maxReceivedMessageSize="2147483647"
>
<readerQuotas/>
</binding>
</basicHttpBinding>
</bindings>
<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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<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>
</configuration>
I've studied several articles but unable to resolve the issue, Can anyone suggest a solution to this problem?

Configuring and installing a WCF app on Windows Server 2012

I am working on a Web Service app. The tools in use for this project are a Windows Server 2012 Standard and Visual Studio Pro 2013. App is in C#, .NET 4.5
At this early point in the development of this app., it's in the proof of concept stage. No database, nothing fancy at all; trying to get the basic architecture to work. Running in the development environment, everything works fine. Publishing to the server does not work. I get 404 - File or directory not found when I try to open this page in a browser. On my development system/personal web server, I can see the results of the app running on the page displayed.
I have looked at a number of tutorials and step-by-step instructions on how to do this. This and this was very helpful.
After some work on the server side, I got the web deploy feature to work from my development system to the server. I have also tried other install techniques.
I have reached a wall in narrowing down the problem because I don't know IIS architecture all that well and that seems to be the problem, unless I have misunderstood some aspect of running my test/proof of concept. I have not gotten much help from my service provider running the server debugging this.
Any thoughts on how to narrow this problem; where to look, alternative tests to try, much appreciated.
web.config (this is the generic version generated by
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="Test.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8371/Design_Time_Addresses/Test/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="Test.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</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>
</system.serviceModel>
</configuration>
adding this to the config solved the problem.
<system.webServer>
<handlers>
<add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="File" requireAccess="Script" preCondition="integratedMode" />
</handlers>
</system.webServer>

Basic WIndows Workflows 4 Persistance in a webserver hosted .xamlx services not working

I'm trying to create a Windows Workflow 4 Service hosted in IIS. I've configured the service as below
<system.serviceModel>
<services>
<service name="ApprovalService" behaviorConfiguration="ApprovalServiceBehavior">
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ApprovalServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
<sqlWorkflowInstanceStore connectionStringName="WorkflowPersistence" />
<workflowIdle timeToPersist="0" timeToUnload="0:05:0"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
The service does not persist! There's nothing magical in the service like custom persisting of values, etc. I've got it working in another service that does have a custom persistance method, but I can't figure out the difference.
Perhaps my service is erroring out, but I can not seem to figure out how to step into debugging either.
Any help would be greatly appreciated!
Assuming the name of your service element and the SQL connection string are correct you workflow should persist as soon as it goes idle. Did you try adding a Delay activity to ensure it goes idle or a Persist activity to force it to persist?
Try adding tracking or tracing to see what is going on. Something like
<system.diagnostics>
<sources>
<source name="System.Activities"
switchValue="Verbose">
<listeners>
<add name="textListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="MyTraceLog.txt"
traceOutputOptions="ProcessId, DateTime" />
</listeners>
</source>
</sources>
</system.diagnostics>

Resources