Web SVC works on HTTP but not HTTPS - web-services

I've tried several solutions posted around the net, but none of them appear to work.
The response I get to the web service method is:
404: File or directory not found.
When I visit the http version of the AddressService.svc file, I get a service description. When I visit the method (AddressService.svc/ValidateAddress) I get "GET method not allowed", which is expected because it's a POST method only. When I try the https version of the AddressService.svc page I also get the service description. However, when I try to visit the method (AddressService.svc/ValidateAddress), I get the 404/not found result.
Here is what I've got in my web.config currently:
Binding:
<bindings>
<basicHttpBinding>
<binding name="WebServiceSoap">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
Service:
<service name="DefiningVoiceWeb.AddressService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" contract="DefiningVoiceWeb.IAddressService" behaviorConfiguration="web" />
<host>
<baseAddresses>
<add baseAddress="https://www.definingvoice.com/AdminOnly/AddressService.svc" />
</baseAddresses>
</host>
</service>
Service Behavior:
<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" />
</behavior>
</serviceBehaviors>
And I've also added this for CORS:
<httpProtocol>
<customHeaders>
<clear />
<add name="X-Powered-By" value="ASP.NET" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST" />
</customHeaders>
</httpProtocol>
Here's my IAddressService declaration:
[ServiceContract]
public interface IAddressService
{
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/ValidateAddress",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
Address ValidateAddress(Address address);
}
And the AddressService.svc:
<%# ServiceHost Language="C#" Debug="true" Service="DefiningVoiceWeb.AddressService" CodeBehind="AddressService.svc.cs" %>
I've tried solutions from these pages, but none of them appear to work for me:
How to convert wcf http web service to https
SVC WebService works over HTTP, fails over HTTPS
WCF Bindings Needed For HTTPS
I'm happy to try one of the solutions above if it's possible I did something wrong. Let me know if I need to supply more details.
Thanks in advance.
After reading through the link provided by #pepo I found the problem. Here are the sections I edited with the final working configuration:
Service:
<service name="DefiningVoiceWeb.AddressService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" contract="DefiningVoiceWeb.IAddressService" behaviorConfiguration="webHttpBehavior" />
<host>
<baseAddresses>
<add baseAddress="https://www.definingvoice.com/AdminOnly/" />
</baseAddresses>
</host>
</service>
Binding:
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>

Well, why do you edit basicHttp binding configuration when you are using weHttpBinding?
This SO answer might help you (I didn't test it though). There is a nice article referenced explaining how to set up https with webHttpBinding.

Related

How to Call Client Machine Hosted WcfService From WebApplication Hosted on Another Server?

I have a WcfService hosted on Console Application on user(client) computer that provides access to document scanner device (Avision AD240) to scan documents and want to call this service from another website (e.g hosted on www.someotherdomain.com).
In summary: my website users work with jetScan document scanner and want to upload scanned images on the server in the website. I've done that in local IIS but I don't know how to address the local hosted service in the remote server hosted web application.
My WcfService Web.Config file looks like:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IScannerService" maxReceivedMessageSize="2147483647">
</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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfServiceScanner.ScannerService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScannerService" contract="WcfServiceScanner.IScannerService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfServiceScanner/WcfServiceScanner/" />
</baseAddresses>
</host>
</service>
</services>
<protocolMapping>
</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"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
and a part of my remote server web application web.config file looks like :
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IScannerService" maxReceivedMessageSize="2147483647"/>
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IScannerService">
<security>
<transport sslProtocols="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/WcfService" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IScannerService" contract="WcfScannerService.IScannerService"
name="BasicHttpBinding_IScannerService" />
<endpoint address="net.tcp://localhost:8090/WcfService" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IScannerService" contract="WcfScannerService.IScannerService"
name="NetTcpBinding_IScannerService">
<identity>
<userPrincipalName value="DESKTOP-KILE609\Hosein" />
</identity>
</endpoint>
</client>
</system.serviceModel>
The code is fine if it is locally accessible.
The following steps may help you:
Make sure the network is working on the other machine.
Check whether the IP address and port are occupied or shielded by the firewall.
Adding ?wsdl in the end of the url,if that works and show you an xml file, the service is reachable.
Thanks.

Error while deploying webservice. Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding

I have been trying to deploy a simple Sync Service in .NET 3.5 in a production IIS server (Made it using the WCF Service Library of VS2008). While deploying and testing it, it has thrown the following error:
"Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [https]."
And this is the web.config
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://194.165.0.8:80/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MobileSyncServiceLibrary.AdventureWorksSyncService" behaviorConfiguration="MobileSyncServiceLibrary.AdventureWorksSyncServiceBehavior">
<endpoint address="http://194.165.0.8:80/PruebaWS/MobileSyncServiceLibrary.AdventureWorksSyncService.svc" binding="basicHttpBinding" contract="MobileSyncServiceLibrary.IAdventureWorksSyncContract" bindingConfiguration="basicHttpBindingConfiguration"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MobileSyncServiceLibrary.AdventureWorksSyncServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<defaultDocument>
<files>
<remove value="Default.htm" />
<remove value="Default.asp" />
<remove value="index.htm" />
<remove value="index.html" />
<remove value="iisstart.htm" />
<remove value="default.aspx" />
<add value="MobileSyncServiceLibrary.AdventureWorksSyncService.svc" />
</files>
</defaultDocument>
</system.webServer>
I have already done the solution pointed out in most posts about this question:
Setting security mode=None
Setting httpsGetEnabled="false"
All answers that I have seen, point to this two settings, but I have not been able to fix the error on the configuration.
Any ideas on what Im missing or what do i need to change? This is the current exception the service is throwing.
[ServiceActivationException: The service '/PruebaWS/MobileSyncServiceLibrary.AdventureWorksSyncService.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) +594083
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +238
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +327
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92
This are the current bindings on the site.
Ok. Found the solution. I misread the multiple binding solution.
I read the following section as telling the site to which binding i was pointing the service.
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://194.165.0.8:80/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
When it is the exact opposite according to this answser.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/03687d4d-87dd-44b3-b945-05787ea93bd0/could-not-find-a-base-address-that-matches-scheme-http-for-the-endpoint-with-binding?forum=wcf
I was causing the problem, the service was being redirected to the https binding
So i changed the prefix to https://194.165.0.8:443 to filter out the https and send it to the http connection.

Exposing RESTful WCF service over HTTPS

I've poked around dozens of blogs and SO questions and still can't get this to work. I can load my service over HTTP, but I get the following error over HTTPS:
Could not find a base address that matches scheme http for the endpoint with binding secureWeb. Registered base address schemes are [https].
I'm hosting locally in IIS under an SSL site that works for several other apps already. Here is the config that I am trying to get working; any suggestions would be greatly appreciated!
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="secureWeb">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" httpHelpPageEnabled="false" httpsHelpPageEnabled="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Example.TestService">
<endpoint binding="webHttpBinding" bindingName="secureWeb" bindingNamespace="http://example.com/services"
behaviorConfiguration="webBehavior"
contract="Example.ITestService" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="Test.svc" service="Example.TestService" factory="Example.Common.ServiceModel.Activation.FlatWsdlServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
In addition to everything else already said, I think you should have bindingConfiguration="secureWeb" instead of bindingName="secureWeb"
(e.g. <endpoint binding="webHttpBinding" bindingConfiguration="secureWeb"...)
Based on a review of your WCF configuration, I think the issue may be related to the service metadata configuration. The configuration seems to specify that the metadata is available via http and https, but the endpoints only contain bindings for secure https (secureWeb).
In the following line, change the httpGetEnabled value from true to false.
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
Note: The Creating a WCF RESTful Service And Secure It Using HTTPS Over SSL blog post mentions changing the service metadata options toward the end:
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
Lastly, we need to update the metadata publishing endpoint to use
HTTPS as well:

WCF Service in IIS bindings

I have inherited a WCF project which is hosted under IIS. Its part of a regular website i.e. there are human usable pages as well.
The site is configured in IIS with the following 2 bindings:
1: https://www.example.com/
2: http://www.example.com:8080/
If I visit http://www.example.com:8080/my-service.svc?wsdl I get a WSDL file returned as expected.
If I visit https://www.example.com/my-service.svc?wsdl I get told I need to visit http://www.example.com:8080/my-service.svc?wsdl to create a client.
There is no binding section under system.serviceModel in web.config.
What I want to know is, how does the service know it is associated with the second IIS binding and not the first.
system.ServiceModel follows:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="FormsAuthBehavior" type="My-WCF.FormsAuthBehaviorExtensionElement, EcobuttonWebService" />
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="FormsAuthenticated">
<!--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" />
<!--Pre-authenticates client with server to generate FormsAuthentication cookie. Cookie is submitted with each WCF request.-->
<!--NB: set throwsSecurityExceptions="false" when updating service references in client apps.-->
<FormsAuthBehavior throwsSecurityExceptions="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="My-Service" behaviorConfiguration="FormsAuthenticated" />
</services>
</system.serviceModel>
Configure WCF Service for HTTP Transport Security
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
Specify your service and service endpoint as shown in the following XML.
<services>
<service name="MySecureWCFService.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="MySecureWCFService.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
Enable httpsGetEnabled
<serviceBehaviors>
<serviceMetadata httpsGetEnabled="true"/>
</serviceBehaviors>
References:
MSDN
Seven simple steps to enable HTTPS on WCF WsHttp bindings

Setting up Secured SSL, WCF using windows authentication

Ok, I really need help getting this setup. Currently i have an ssl cert installed. I have a wcf service installed in iis as an application. I have set it to require ssl and i am able to connect to the service. Issue is i want windows authentication. and i want to disable anonymous security. Soon as i disable anonymous and keep windows auth. i get an 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.etc etc...."
When i turn anonymous back on with windows auth. Yes i can access the service but it doesn't use the windows auth.. its weird because other files such as test.html for example still require username/password. i don't know how to properly restrict a webservice for windows auth using ssl... can anyone help me?? please
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WcfConcur.ConcurService">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="TransportSecurity"
contract="WcfConcur.IConcurService"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
on the client side, i add a reference to the wcf. and it downloads this automatically. thing is my intial wcf address that is hosted is https://address/whatever.svc and when it downloads it shows http://internal address i don't know if thats the issue
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
<system.serviceModel>
<client>
<endpoint address="http://internal address/wcfConcurService/ConcurService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConcurService"
contract="wcfConcurRef.IConcurService" name="BasicHttpBinding_IConcurService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IConcurService" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
The error message thrown, when anonymous access is disabled, seems to indicate an issue with the client configuration.
The client configuration appears to be using the basicHttpBinding which is different from the server configuration which is using wsHttpBinding. To resolve the binding issue, you should copy the server binding configuration to the client configuration file and then update the client endpoint to use the new binding configuration.
Your client configuration should look something like:
<system.serviceModel>
<client>
<endpoint address="https://enter-external-address-here/wcfConcurService/ConcurService.svc"
binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
contract="wcfConcurRef.IConcurService" name="BasicHttpBinding_IConcurService" />
</client>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>