self hosted wcf with ssl with webHttpBinding - wcf

I'm have created a self hosted WCF service that act as REST API service with webHttpBinding and support of CORS. I consume this service from the browser.
When I tried to add https, it didn't work.
I created the CERTS, and combine them according to this tutorial:
https://www.youtube.com/watch?v=ugpPSNxtAmY
my config is:
<system.serviceModel>
<services>
<service name="MyService.MyService">
<endpoint address="" binding="webHttpBinding" contract="MyService.IMyService" behaviorConfiguration="jsonBehavior">
<identity>
<dns value="MyMachine" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="crossOriginResourceSharingBehavior" type="Company.Common.EnableCrossOriginResourceSharingBehavior, Company.Common" />
</behaviorExtensions>
</extensions>
<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>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp />
<crossOriginResourceSharingBehavior />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding crossDomainScriptAccessEnabled="true" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288"
transferMode="Buffered">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
</webScriptEndpoint>
</standardEndpoints>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
When I try to consume I got an error.
How can I do it.
The client of this service is a browser

This tutorial is awesome:
http://www.allenconway.net/2012/05/creating-wcf-restful-service-and-secure.html
it explains exactly what shall be done

Related

WCF Ws-Seciurity service configuration

I'm having truble with configuration around my WCF service and WS-Seciurity.
I don't have access to the client side, so far I'm trying to use SoapUI as a client with WS-A adressing, userName, Password and WSS Password Type 'PasswordDigest' options.
I use IIS and https with a simple certificate, .NET 4.7.
I've tried many versions, but without success. I just want to find simplest, working solution to read 'Seciurity' header from SoapUI/client request with WS-Seciurity PasswordDigest options enabled.
The current error with the current config file 'InvalidSecurity' 'An error occurred when verifying security for the message'
<system.serviceModel>
<protocolMapping>
<add scheme="https" binding="wsHttpBinding"/>
</protocolMapping>
<services>
<service name="SoapService" behaviorConfiguration="SoapServiceConf">
<!--<endpoint address="SoapService" binding="wsHttpBinding" contract="MPA.SoapService.References.ServiceReference.SentSOAP" /> -->
<endpoint address="" binding="wsHttpBinding" contract="Interfaces.ISoap" bindingConfiguration="wsHttpBind"/>
<endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding maxReceivedMessageSize="10485760" name="wsHttpBind">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Basic"/>
<message clientCredentialType="UserName" algorithmSuite="Default" establishSecurityContext="false" />
</security>
<reliableSession enabled="false" />
<readerQuotas maxArrayLength="10485760" maxDepth="1024" maxStringContentLength="10485760" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SoapServiceConf">
<serviceCredentials>
<serviceCertificate findValue="soapservice"
storeName="My"
x509FindType="FindByIssuerName" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
<behavior name="MyServiceTypeBehaviors" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thanks.

WCF picking basicHttpBinding & ignoring the defined customBindings

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<bindings>
<customBinding>
<binding name="httpBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
</binding>
<binding name="httpsBinding">
<binaryMessageEncoding/>
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
</binding>
</customBinding>
</bindings>
<services>
<service name="MyNamespace.MyIService" behaviorConfiguration="MyNamespace.MyIService" >
<endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
binding="customBinding" contract="MyNamespace.MyIService"
name="httpBinding"/>
<endpoint address="https://wcf-client-url/virtualDirectory/MyService.svc"
binding="customBinding" bindingConfiguration="httpsBinding"
contract="MyNamespace.MyIService" name="httpsBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyNamespace.MyIService" >
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<client>
<endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
binding="customBinding"
bindingConfiguration="httpBinding"
contract="MyNamespace.MyIService"
name="httpBinding" />
<endpoint address="https://wcf-client-url/virtualDirectory/MyService.svc"
binding="customBinding"
bindingConfiguration="httpsBinding"
contract="MyNamespace.MyIService"
name="httpsBinding" />
</client>
</system.serviceModel>
I have the above configuration in a WCF service that is hosted in IIS. I can successfully browse to the service in the browser, as you can observer i want to use a customBinding.
When i use visual studio to add a reference to this service in my client application using VS inbuilt add service reference dialogue, below is the client endpoint that visual studio creates for me.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyIService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyIService"
contract="ServiceReference1.MyIService" name="BasicHttpBinding_MyIService" />
</client>
</system.serviceModel>
What i'm not understanding is why VS is creating for me a client basicHttpBinding yet i have defined a customBinding on the server.
Also, when i test my service in "WCF Test Client" and then double click the config file in WCF Test Client, i see that indeed it displays the below config in the Test Client.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyIService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myPCHostName/virtualDirectory/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyIService"
contract="MyIService" name="BasicHttpBinding_MyIService" />
</client>
</system.serviceModel>
</configuration>
I'm sort of new to this WCF development & i'm not clearly understanding how my customBinding are being ignored.
From my config above, is BasicHttpBinding being set any where as the default binding, or is there away i can completely remove it even though i can't seem to figure where its being set from in that configuration.
try to specify behaviorConfiguration and bindingConfiguration for both endpoints on service side. You have specified bindingConfiguration only for https endpoint, and have not done this for behaviors at all.
Should be something like
<bindings>
<customBinding>
<binding name="httpBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
</binding>
<binding name="httpsBinding">
<binaryMessageEncoding/>
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
</binding>
</customBinding>
</bindings>
<services>
<service name="MyNamespace.MyIService" behaviorConfiguration="MyNamespace.MyIService" >
<endpoint address="http://wcf-client-url/virtualDirectory/MyService.svc"
binding="customBinding"
contract="MyNamespace.MyIService"
bindingConfiguration="httpBinding"
behaviorConfiguration="httpEndpoint"
name="httpBinding"/>
<endpoint address="https://wcf-client-url/virtualDirectory/MyService.svc"
binding="customBinding"
bindingConfiguration="httpsBinding"
behaviorConfiguration="httpEndpoint"
contract="MyNamespace.MyIService"
name="httpsBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="httpEndpoint" >
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>

A relative URI cannot be created because the 'uriString' parameter represents an absolute

I have created a simple WCF application to host in sharepoint server.
When deployed i got this error
A relative URI cannot be created because the 'uriString' parameter represents an absolute URI.http://<MySharepointserver>:28000/_vti_bin/WCF/service.svc
Here is my service Web.config
<system.serviceModel>
<services>
<service behaviorConfiguration="AssignmentCreatorMK1.ISAPI.ServiceBehaviour" name="AssignmentCreatorMK1.ISAPI.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEmployeeService" contract="AssignmentCreatorMK1.ISAPI.IService" name="BasicHttpBinding_IEmployeeService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IEmployeeService" maxReceivedMessageSize="2147483647" messageEncoding="Mtom">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="AssignmentCreatorMK1.ISAPI.ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
can somebdy please help me out here ?

Configuring WCF for wsHttpBinding

I have a WCF service that works using basicHttpBinding, I'm trying to configure it to go over https and authenticate with a SQL membership provider, and to do this I'm trying to convert it to use wsHttpBinding.
However, with the updated config I get the following error when I try to connect with the client:
Could not find default endpoint element that references contract 'KFileService.IKFileWcfService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Here's the relevant portion of the web.config for the server:
<system.serviceModel>
<protocolMapping>
<remove scheme="http" />
<add scheme="https" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IKFileWcfServiceBinding" />
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior name="KFileWcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="SqlMembershipProvider" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="KFileWcfServiceBehavior" name="KFileWcfService">
<endpoint address="https://localhost:36492/KFileWcfService.svc"
binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IKFileWcfServiceBinding"
name="wsHttpBinding_IKFileWcfService" bindingName="wsHttpBinding_IKFileWcfServiceBinding"
contract="KFileWcfService.IKFileWcfService">
<identity>
<certificateReference storeLocation="CurrentUser" />
</identity>
</endpoint>
</service>
</services>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding_IKFileWcfServiceBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Message">
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
And here's the client side:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding_IKFileWcfService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:36492/KFileWcfService.svc"
binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IKFileWcfService"
contract="KFileWcfService.IKFileWcfService" name="wsHttpBinding_IKFileWcfService" />
</client>
</system.serviceModel>
I've done my best to go through all the existing questions and examples already, but haven't had any luck. Can anyone tell me what I'm doing wrong?
Edit:
For further reference, here's the server side configuration that works with basicHttpBinding:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<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" />
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="KFileWcfService">
<endpoint address="https://localhost:36492/KFileWcfService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IKFileWcfService" contract="KFileService.IKFileWcfService" name="BasicHttpBinding_IKFileWcfService" />
</service>
</services>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IKFileWcfService" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="32" maxStringContentLength="100000" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
And client:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IKFileWcfService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:36492/KFileWcfService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IKFileWcfService"
contract="KFileService.IKFileWcfService" name="BasicHttpBinding_IKFileWcfService" />
</client>
</system.serviceModel>
The type of the service contract on the client which you're trying to use, based on your error messsage:
KFileService.IKFileWcfService
The type of the service contract interface which you have on your client config:
KFileWcfService.IKFileWcfService
They should be the same. Change the client config to
... contract="KFileService.IKFileWcfService" ...
And it should work.

Error publishing WCF service with net.tcp bindings

I'm trying to publish a WCF service on IIS 7.5 net.tcp enabled and I get the following error:
Could not find a base address that matches scheme net.tcp for the
endpoint with binding NetTcpBinding. Registered base address schemes
are [http].
Attached the web.config
<system.serviceModel>
<services>
<service name="BLAlgorithmService" behaviorConfiguration="BLAlgorithmService.Behavior">
<host>
<baseAddresses>
<add baseAddress="http//localhost:56795/Algorithemservice" />
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="DuplexBinding"
contract="IBLAlgorithmService" />
<endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BLAlgorithmService.Behavior" >
<serviceMetadata httpGetEnabled="true"/>
<serviceThrottling maxConcurrentSessions="10000" />
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
<behavior name = "MEX">
<serviceMetadata httpGetEnabled="true"/>
<serviceThrottling maxConcurrentSessions="10000" />
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="DuplexBinding"
maxReceivedMessageSize="64000000"
maxBufferPoolSize="64000000"
closeTimeout="02:50:00"
openTimeout="02:50:00"
receiveTimeout="02:50:00"
sendTimeout="02:50:00">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<reliableSession ordered="true"
inactivityTimeout="10:50:00"
enabled="false" />
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
Your base address should be net.tcp://localhost:56795/Algorithemservice