Exception: The client certificate is not provided - certificate

I am trying to configure WCF service with security. I have generated 2 certificates (for server and client side) stored in LocalComputer\Personal Certificates. My configuration is:
Server:
<netTcpBinding>
<binding name="defaultBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</netTcpBinding>
<service name="..." behaviorConfiguration="serviceBehavior">
<endpoint address="..." binding="netTcpBinding" bindingConfiguration="defaultBinding" contract="...">
<identity>
<dns value="ClientSide"/>
</identity>
</endpoint>
</service>
<behavior name="serviceBehavior">
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" storeName="My" findValue="ServerSide" x509FindType="FindBySubjectName"/>
<clientCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck"/>
</clientCertificate>
</serviceCredentials>
<behavior>
Client:
<netTcpBinding>
<binding name="defaultBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</netTcpBinding>
<endpoint name="..." binding="netTcpBinding" bindingConfiguration="defaultBinding" contract="..."
behaviorConfiguration="endpointBehavior">
<identity>
<dns value="ServerSide"/>
</identity>
</endpoint>
<behavior name="endpointBehavior">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck"/>
</serviceCertificate>
<clientCertificate storeLocation="LocalMachine" storeName="My" findValue="ClientSide" x509FindType="FindBySubjectName"/>
</clientCredentials>
<behavior>
I am getting the exception: The client certificate is not provided. Specify a client certificate in ClientCredentials
I have tried many tutorials, but none of them works. Any suggestion?

The answer is actually in the Exception.
You don't have a client certificate. You define a service certificate for the client certificate with this
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck"/>
</serviceCertificate>
<clientCertificate storeLocation="LocalMachine" storeName="My" findValue="ClientSide" x509FindType="FindBySubjectName"/>
</clientCredentials>
But what you actually should have done is defining a client certificate for the client
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="endpointBehavior">
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" storeName="My" findValue="ClientSide" x509FindType="FindBySubjectName" />
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
This should at least solve your The client certificate is not provided. Specify a client certificate in ClientCredentials exception.

Related

Bad Request REST/SOAP for a WCF Webservice

A WCF service needs to be capable to SOAP and REST format.
It returns Bad Request (400), below is my web config file:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ILoginSVC" allowCookies="true" maxBufferPoolSize="20000000" maxBufferSize="70000000" maxReceivedMessageSize="70000000">
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webHttpBindingILoginSVC" allowCookies="true" maxBufferSize="100000000" maxBufferPoolSize="100000000" maxReceivedMessageSize="100000000" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<services>
<service name="LoginSVC.LoginSVC">
<host>
<baseAddresses>
<add baseAddress="http://localhost:59900/LoginSVC" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="LoginSVC.ILoginSVC">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="REST" binding="webHttpBinding" contract="LoginSVC.ILoginSVC" behaviorConfiguration="RESTEndPointBehaviour">
</endpoint>
</service>
</services>
</system.serviceModel>
In your configuration file, you have not assigned the binding configuration you created, so use the default BasicHttpBinding. You need to explicitly assign the binding you defined (BasicHttpBinding_ILoginSVC) to your endpoint like this:
<endpoint address="" bindingConfiguration="BasicHttpBinding_ILoginSVC" binding="basicHttpBinding" contract="LoginSVC.ILoginSVC" />

Getting error "the provided uri scheme 'https' is invalid expected 'http" from service

I'm getting this error. Do you have any idea?
My code is below;
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Integration" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://test/WcfService/Integration.svc"
binding="basicHttpBinding" bindingConfiguration="Integration"
contract="IntegrationService.Integration" name="Integration" />
</client>
</system.serviceModel>
You may modify your app.config as shown in the following example:
<bindings>
<basicHttpBinding>
<binding name="Integration">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>

Calling JSON Rest service from browser

Want to enable https on my REST JSON WCF service and test it in IE browser.
WSDL is loading with no issues (https://localhost/myservice/Imyservice.svc?WSDL).
But i tried to call a operation ( https://localhost/myservice/Imyservice.svc/Getdata), I am getting
Request Error The server encountered an error processing the request. .
Below is my web.config. Can anyone help me with this
<webHttpBinding>
<binding name="SecureBasicRest" allowCookies="true" >
<security mode="Transport" />
<readerQuotas maxDepth="32"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="svcBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="svcEndpoint">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="myservice.Imyservice" behaviorConfiguration="svcBehavior">
<endpoint binding="webHttpBinding" bindingConfiguration="SecureBasicRest"
behaviorConfiguration="svcEndpoint" name="webHttp"
contract="myservice.Imyservice" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
The root cause is that there is something wrong with the definition of the service endpoint.
<service name="myservice.Imyservice" behaviorConfiguration="svcBehavior">
<endpoint binding="webHttpBinding" bindingConfiguration="SecureBasicRest"
behaviorConfiguration="svcEndpoint" name="webHttp"
contract="myservice.Imyservice" />
</service>
Your idea is correct, we should add a service endpoint with transport security mode. However, the service name should be a fully qualified name of the service implemented class instead of the service interface.
<service name="myservice.myservice"
Feel free to let me know if the problem still exists.

REST Service WebHttpBinding with Http and Https

I have a REST service. This service need to be work with http and https.
I've tried to add two endpoint in my web.config file. But i get this error when i try to browse my service over http:
Could not find a base address that matches scheme https for the
endpoint with binding WebHttpBinding. Registered base address schemes
are [http].
and i get this error when i try to browse over https:
Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].
If i remove one of endpoint from my config file, the both http and https services works fine.
I checked this link: WebHttpBinding with Http and Https
But when i remove endpoints from my config file, the both http and https services runs without any errors on web browser. But when i try to call one of my methods (over a rest client tool) in this service it gets:
500 Internal Server Error.
How can i run this service over http and https without any errors?
My config file is like this:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" bindingConfiguration="webHttpBinding"/>
<add scheme="https" binding="webHttpBinding" bindingConfiguration="webHttpsBinding"/>
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="webHttpBinding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
<binding name="webHttpsBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="MyProject.MyService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpBinding" contract="MyProject.IMyService" />
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpsBinding" contract="MyProject.IMyService" />
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
<!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>-->
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization serviceAuthorizationManagerType="MyProject.RestAuthorizationManager, MyProject"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
here is a sample web.config in order to have both http and https support. i hope solve your problem:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SoapBinding" />
</basicHttpBinding>
<basicHttpsBinding>
<binding name="SecureSoapBinding" />
</basicHttpsBinding>
<webHttpBinding>
<binding name="RestBinding" />
<binding name="SecureRestBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
<mexHttpBinding>
<binding name="MexBinding" />
</mexHttpBinding>
<mexHttpsBinding>
<binding name="SecureMexBinding" />
</mexHttpsBinding>
</bindings>
<client />
<services>
<service behaviorConfiguration="ServiceBehavior" name="Interface.Core">
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="SoapBinding" name="Soap" contract="Interface.ICore" />
<endpoint address="soap" binding="basicHttpsBinding" bindingConfiguration="SecureSoapBinding" name="SecureSoap" contract="Interface.ICore" />
<endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Rest" contract="Interface.ICore" />
<endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="SecureRestBinding" name="SecureRest" contract="Interface.ICore" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="MexBinding" name="Mex" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration="SecureMexBinding" name="SecureMex" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<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" />
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>

EntityFramework failing to connect when downloaded by ClickOnce (vs2010) on Windows 8

A newbie question.
Having completed an application using WCF and EntityFramework (each in different projects), I am trying to deploy it with ClickOnce. In visual studio 2010, the application was published to a directory on my laptop. The files were then copied to a tablet pc running windows 8.
When the program is run, I get a Connection Error with a target machine actively refusing it 127.0.0.1:24324.
This application runs well on my laptop and nowhere is 127.0.0.1 used (by me). The working program (on my laptop) has a class that determines the network I am on and then adjusts the connection string to the appropriate address of the network server.
What happened? And how do I fix it?
Any help or insight would be greatly appreciated.
Edit: The Web.config file for my working machine, the laptop, is:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="LibraryConnection"
connectionString="server=xxx.xxx.xxx.xxx;port=xxxx;user id=id;password=mypassword;database=mydatabase"
providerName="Npgsql" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
The working app.config from the client project is:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_INovaDataService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:24324/DataService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INovaDataService" contract="DataService.INovaDataService" name="BasicHttpBinding_INovaDataService"/>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>