WCF problem with POSTs using ssl (https) - wcf

I currently have a webHttp binding WCF restful service, it works great over http, I can make Post of large sizes due to my webconfig settings, now I am trying to use it over https (ssl), now my gets work fine, but my posts dont, it doesnt work when the file size is over a certain amount, i was wondering why this could be since my webconfig specifies a larger size and it works good over http, here is my relevant webconfig.. any suggestions
Thanks
<system.serviceModel>
<client>
<endpoint binding="webHttpBinding" bindingConfiguration="webHttp"
contract="PrimeStreamInfoServices.IService1" name="Client" />
</client>
<bindings>
<webHttpBinding>
<binding name="webHttp" maxBufferSize="15000000" maxBufferPoolSize="15000000"
maxReceivedMessageSize="15000000">
<readerQuotas maxDepth="15000000" maxStringContentLength="10000000"
maxArrayLength="15000000" maxBytesPerRead="15000000" maxNameTableCharCount="10000000" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="string" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="PrimeStreamInfoServices.Service1Behavior"
name="PrimeStreamInfoServices.Service1">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="webHttp" contract="PrimeStreamInfoServices.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PrimeStreamInfoServices.Service1Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<!--
<serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="TempCa" />
-->
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
</diagnostics>

If you want to use webHttpBinding over SSL then you have configure your binding to use transport security like:
<security mode="Transport">
This link provides some details with sample config to deal with the following error:
Could not find a base address that matches scheme http for the
endpoint with binding WebHttpBinding. Registered base address schemes
are [https]
Sample config from the blog:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="TestServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="TestService">
<endpoint address="" behaviorConfiguration="TestServiceAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="webBinding" contract="TestService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

Related

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 webHttpBinding for both HTTP and HTTPS?

I'm having a really hard time finding how to host a WCF service in an IIS site that works on both HTTP and HTTPS. I've done about 10 hours of research including just about every link on StackOverflow that relates to this issue and tried many different combinations and have not yet been able to get both working at the same time. Right now only HTTPS works with the below configuration:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="http">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
<binding name="https">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyWcfServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<services>
<service name="MyWcfService">
<endpoint address="" behaviorConfiguration="MyWcfServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="http" contract="IMyWcfService" />
<endpoint address="" behaviorConfiguration="MyWcfServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="https" contract="IMyWcfService" />
</service>
</services>
</system.serviceModel>
I think you need to specify different endpoint "address" values in your service configuration.
For example:
<services>
<service name="MyWcfService">
<endpoint address="" behaviorConfiguration="MyWcfServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="http" contract="IMyWcfService" />
<endpoint address="secure" behaviorConfiguration="MyWcfServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="https" contract="IMyWcfService" />
</service>
</services>

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.

WCF Endpoint Address not working

Can someone please tell me what I'm doing wrong below? I have been fighting with this for hours and believe that I have it right, but I have to be missing something. Basically for every service I have I would like to have to addresses. These services are to be hosted in IIS. I have been testing with IIS Express. My expectation is that I would access the services at /AuthService.svc/soap and /AuthService.svc/json, but that doesn't seem to be working. Below is the config I'm using.
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="SecureBinding" allowCookies="true" maxReceivedMessageSize="67108864">
<readerQuotas maxArrayLength="67108864"/>
<security mode="Transport"/>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="SecureBinding" allowCookies="true" maxReceivedMessageSize="67108864">
<readerQuotas maxArrayLength="67108864"/>
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="AuthService" behaviorConfiguration="DefaultServiceBehavior">
<endpoint address="soap"
binding="basicHttpBinding"
bindingConfiguration="SecureBinding"
contract="FormsAuthenticatingServices.Interfaces.IAuthService" />
<endpoint address="json"
binding="webHttpBinding"
bindingConfiguration="SecureBinding"
behaviorConfiguration="jsonBehavior"
contract="FormsAuthenticatingServices.Interfaces.IAuthService" />
</service>
<service name="DataService" behaviorConfiguration="DefaultServiceBehavior">
<endpoint address="soap"
binding="basicHttpBinding"
bindingConfiguration="SecureBinding"
contract="FormsAuthenticatingServices.Interfaces.IDataService" />
<endpoint address="json"
binding="webHttpBinding"
bindingConfiguration="SecureBinding"
behaviorConfiguration="jsonBehavior"
contract="FormsAuthenticatingServices.Interfaces.IDataService" />
</service>
</services>
</system.serviceModel>
You should get the SOAP based metadata at /authservice.svc?wsdl and the REST based operations starting from the URI /authservice.svc/json
You will not see anything in a browser by hitting /authservice.svc/soap as SOAP assumes XML messages will be POSTed to the service whereas the browser is performing a GET. To use the SOAP service create a client project and generate a proxy using Add Service Reference pointing at the WSDL
In addition to Richard's answer, make sure the name attribute on the <service> element is the fully qualified name of the service class.

What are the steps to setup SSL to work with WCF on Azure?

Please post the steps you have taken to setup SSL to work with WCF on Azure.
I have my valid certificate uploaded successfully (using cspack) and working with the rest of the site, but after adding it, my previously working WCF service stopped working. (All I get is a 404 error back to Silverlight, which is not very helpful. Up votes to whomever comes up with some better logging I could be doing too to help diagnose the problem too!)
I've tried many variations on this configuration:
<system.serviceModel>
<!--start added for SSL-->
<bindings>
<basicHttpBinding>
<binding name="SecureBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<!--end added for SSL-->
<behaviors>
<!--start added for SSL-->
<endpointBehaviors>
<behavior name="DisableServiceCertificateValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None"
revocationMode="NoCheck" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
<!--start added for SSL-->
<serviceBehaviors>
<behavior name="Silverheat.Cloud_WebRole.API.DataServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!-- certificate checking removed -->
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="Silverheat.Cloud_WebRole.API.DataServiceBehavior"
name="Silverheat.Cloud_WebRole.API.DataService">
<!--<endpoint address="" binding="basicHttpBinding" contract="Silverheat.Cloud_WebRole.API.DataService" />-->
<endpoint bindingConfiguration="SecureBasicHttpBinding"
behaviorConfiguration="DisableServiceCertificateValidation"
address="" binding="basicHttpBinding"
contract="Silverheat.Cloud_WebRole.API.DataService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Unfortunately, debugging this and getting more info is really hard because I cannot step through and debug with any configuration remotely like I'd use on the live server because the bindings tag has problems on debug (but not live).
Thanks for your help and interest!
Wow! Its alive! Its working!!
Still doesn't work in debug (security exception), but I'll live with that until the next release.
Here's the configuration that worked:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SecureBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Silverheat.Cloud_WebRole.API.DataServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="Silverheat.Cloud_WebRole.API.DataServiceBehavior"
name="Silverheat.Cloud_WebRole.API.DataService">
<endpoint bindingConfiguration="SecureBasicHttpBinding"
address="" binding="basicHttpBinding"
contract="Silverheat.Cloud_WebRole.API.DataService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
(I think it was "mexHttpsBinding" that made it finally work, although I don't entirely understand why it needs meta data after its already configured, back to the books I guess)
I'd still like to know how to enable some kind of logging for WCF, but I'll poke around this great site a bit more and I'm sure I'll find an answer.