WCF service under https environment - https

I've created and tested WCF service, everything works fine.
When I deployed to TEST environment and tried to open https://my.site/myapp/EnrollmentService.svc I've got the error message:
Could not find a base address that
matches scheme http for the endpoint
with binding
MetadataExchangeHttpBinding.
Registered base address schemes are
[https].
Internet showed me that I need to add some more configuration options:
http://www.codeproject.com/KB/WCF/7stepsWCF.aspx
I've added some settings to service web.config file. Now it looks like in the following way:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint
address="https://my.site/myapp/EnrollmentService.svc"
binding="basicHttpBinding"
bindingConfiguration="TransportSecurity"
contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
Actually, I've added "bindings" section and specified it for my endpoint.
But this changed nothing...
Please advise, what I need to do. Thanks a lot!
P.S. Are there any differences in WCF service consuming from https and http resources?

When you want to expose your service only over HTTPS (site does not support HTTP at all) you can't use anything that is dependent on HTTP. Your current configuration exposes help page on HTTP and also mex endpoing (with wrong contract) on HTTP. So try this:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

You have got http metadata endpoint that should be changed to https as below.
<serviceMetadata httpsGetEnabled="True"/>
Also if not necessary you should remove the mex and https metadata endpoint from production as a best practice.

To fix the problem by allowing HTTP, you need to add a http binding in IIS:
Navigate to your site in IIS
Click 'Bindings...' in the Actions panel on the right.
Click 'Add'
Select 'http' and OK out.
Alternatively, you can prevent the problem by either deleting the line, or changing:
<serviceMetadata httpGetEnabled="True"/>
to:
<serviceMetadata httpsGetEnabled="True"/>

Related

Increasing WCF Performance

We have design AJAX – Enable WCF web services for our mobile application. Web service methods returns data in JSON format. We are observing delay in calling web services and binding it to mobile widget. The size of data in approximately 50K.
According to Code Project , we have applied changes to web.config file of WCF Web Service.
Similarly, following one of the stackoverflow question we are trying to increase message size. Now, problem is how we should apply changes to our current web.config file so that message size is increase. We are using default NET 4.0 setting. Also, do we need to define end point on our client web.config file. Can someone provide client side web.config?
Our current server web.config settings is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!--Increase WCF Performance-->
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<!--Increase WCF Performance-->
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" />
</service>
</services>
</system.serviceModel>
</configuration>
Can anyone confirm if changes I applied is valid or not and mark it has confirm answers?
<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!--Increase WCF Performance-->
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--Increase WCF Performance-->
<bindings>
<webHttpBinding>
<binding name="webHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" bindingConfiguration="webHttp" />
</service>
</services>

Publishing a WCF service using visual studio 2013, cannot find service afterwards

I am trying to develope a silverlight page which uses a WCF service to communicate to my database (external database on a webhotel). It all works fine locally, but when I deploy the page and run it, I get the error "The remote server returned an error: NotFound".
<system.serviceModel>
<bindings>
<customBinding>
<binding name="FundFinder.Web.FundSilverlightService.customBinding0">
<binaryMessageEncoding />
<httpTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="FundFinder.Web.FundSilverlightService">
<endpoint address="http://subdomain.domain.com" binding="customBinding" bindingConfiguration="FundFinder.Web.FundSilverlightService.customBinding0"
contract="FundFinder.Web.FundSilverlightService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
I am not sure if I have configured the service correctly, the above is simply that which Visual Studio gave me when I added the service to the solution.
This is a generic error. Please turn on debug in web.config and turn the exception details
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors> ## Heading ##
</behaviors>
see what exception its throwing.

WCF Service, the type provided as the service attribute values...could not be found

I have this issue a long time ago and just cannot recall how to resolve it or perphaps its something new. I created a WCF service which I will later use in web application that calls the WCF service amongst others from a remote location. Right now I am trying to host in IIS and even tried the WCFTestClient. The error I get when I try to browse to the service; is the following:
The type MyService.Service1 provided as the Service attribute
value in the ServiceHost directive, or provided in the
configuration element system.serviceModel/serviceHostingEnvironment/
serviceActivations could not be found.
I figured its probably my web.config file but I cannot see whats wrong:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="false" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding"
contract="WcfRules2.IServiceS" behaviorConfiguration="web"/>
<endpoint address="mex"
binding="webHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
I would like this to be eventually a rest service delivering data in json format.
Check your .svc file and see what service it's referencing - probably MyService.Service1, which doesn't exist in your config. It looks like it should be referencing WcfInstanceRules2.Service1.

"Baseaddress not found"-error when deploying WCF service on GoDaddy

I'm trying to deploy a WCF-service, but I'm having dificulties getting the final bits to work. I'm not a deployment guru in any way, so please bear with me.
I'm using a WebHttpBinding to make Ajax calls to the service using JSON, but I receive the error: "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [].".
Here is a snippet of my web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://mysite.com/" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<bindings>
<webHttpBinding>
<binding name="webHttp">
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="string" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="LicenseManager.LicenseService" behaviorConfiguration="ServiceAspNetAjaxBehavior">
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" contract="LicenseManager.ILicenseService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://mysite.com/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I've made so many changes and tried so many options that I honestly lost overview of what I'm doing. I hope you can find that tiny error that make it all work.
Thank you.
Is your site running directly under http://mysite.com, or is it running under an application/vdir under that site? If so, add the application in your <baseAddressPrefixFilter> element:
<baseAddressPrefixFilters>
<add prefix="http://mysite.com/MyApplication" />
</baseAddressPrefixFilters>
I don't think you need the trailing / either - but I don't think that's causing the issue.
Hopefully this helps! Let em know and I'll update my answer accordingly.
The error was caused by a silly mistake made by me.
My DNS was not set up yet, so I used GoDaddy's "Preview DNS" feature that lets me view the website before the DNS is set up. I used the preview address (mydomain.com.previewdns.com) when I should just have used mydomain.com.
My bad, thanks for the help!

Why do I need to rebuild a WCF AJAX Service that didn't change while debugging?

I have a WCF based service that I use to expose AJAX functionality. Sometimes the service fails when I start a new debugging session (even if I make no changes to the service itself). A rebuild all fixes the issue. I never have this issue in production, just while debugging. I use IIS 7 to debug and have disabled all recycling. Below is my config.
Does anyone know why this happens? Is there another way I can configure the service?
Thanks!
Jon
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SomeService.MyAjaxServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="SomeService.MyAjaxService">
<endpoint address="" behaviorConfiguration="SomeService.MyAjaxServiceAspNetAjaxBehavior" binding="webHttpBinding"
bindingConfiguration="webBinding"
contract="SomeService.MyAjaxService" />
<endpoint address="" behaviorConfiguration="SomeService.MyAjaxServiceAspNetAjaxBehavior" binding="webHttpBinding"
bindingConfiguration="sslWebBinding"
contract="SomeService.MyAjaxService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="sslWebBinding">
<security mode="Transport">
</security>
</binding>
<binding name="webBinding">
<security mode="None">
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
I ended up having to add batch="false" in the web config. I still need to investigate the full ramifications of this, but at least I don't have to rebuild the service all the time.
Cheers,
Jon

Resources