WCF Service 4.0 --- maxReceivedMessageSize ain't effectively used - wcf

I am building a WCF service with framework 4.0 for a special application in house. I have a big array of object to pass from the server to the WPF client. If the array is small enough, everything works fine but if it's over the standart size limit, it doesn't. I tried to change the web.config with the parameter maxReceivedMessageSize but the max size limit error still show with the original value of 65536 even if I put a extreme maxReceivedMessageSize of 1000000000. Here is the web.config as now :
<?xml version="1.0"?>
<behaviors>
<serviceBehaviors>
<behavior name="commonBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="longConnections" maxBufferSize ="1000000000" maxReceivedMessageSize="1000000000"/>
</basicHttpBinding>
</bindings>
<services>
<service name ="MiralisWebServices.HMI_Router" behaviorConfiguration="commonBehavior">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="longConnections"
contract="MiralisWebServices.IHMI_Router"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
I am still a beginner with web.config with framework 4.0. I hope you guys could help.
Thanks

I think that setting change is also required on the client config.

Related

WCF Rest Service - worked great ... Until SSL

I have a WCF Rest service that has been running very smoothly. I just got my SSL cert and installed it in IIS, added an auto redirect to https (basically, forcing https). Now, if I go to "website/ServiceDirectory/Service.svc, I still get the "You have created a service" message, but when I attempt to actually call the service, I'm getting 404 not found. I have already looked through numerous articles. I've disabled http/enabled https. I've ensured I enabled "Transport" security in the binding..Not sure if I'm just missing something or what's going on. Here's my web config, but I'm beginning to think it may be something in IIS
<system.serviceModel>
<client>
<endpoint address=""
binding="webHttpBinding" bindingConfiguration="WebBinding"
behaviorConfiguration="web"
contract="EngageService.IEngage" name="win"/>
</client>
<bindings>
<webHttpBinding>
<binding name="WebBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service behaviorConfiguration="ServiceBehavior" name="EngageService.Engage1">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
contract="EngageService.IEngage" bindingConfiguration="WebBinding" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp defaultOutgoingResponseFormat="Xml"/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<!--<add binding="basicHttpBinding" scheme="http"/>-->
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
In IIS, the service is configured as an application, and as I stated it was working perfectly before I switched to https. Does anyone either see something wrong with my config file, or know of any IIS configuration items I may need to check/change?
Thanks
Ok so this boiled down to the protocolmapping section. It seems that without this mapping, webhttpbinding defaults to http. Added the webhttpbinding, including the entire section to make it easier to spot - hopefully this helps someone else one day.
<protocolMapping>
<!--<add binding="basicHttpBinding" scheme="http"/>-->
<add binding="basicHttpsBinding" scheme="https"/>
<add binding="webHttpBinding" scheme="https" bindingConfiguration="WebBinding"/>
</protocolMapping>
If you have tried all of the other articles and still can't get it - try the above. It breaks http, but I imagine only because you're stealing the endpoint. If you configured a secondary http binding, I would bet it would work perfectly.

Hosting WCF service on IIS (The resource cannot be found)

I am making WFC service. When I debug it from Visual Studio all is ok, but I've faced with problem when I deploy it on real IIS.
After deploying I still can get WSDL but when I request WebGet method (which returns a simple XML document) method I got the following error:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
What can be cause of problem?
My Web.Config:
<system.serviceModel>
<services>
<service name="XXXX.TSDX.UI.TsdxService">
<endpoint
address="Tsdx"
binding="webHttpBinding"
bindingConfiguration="TestBinding"
behaviorConfiguration="RESTFriendly"
contract="XXXX.TSDX.UI.ITsdxService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="TestBinding" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTFriendly">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Verify that the correct version of the .NET framework selected in the ASP.NET tab (in IIS) for your application
If you are hosting this service in MVC app please make sure to add below line to ignore controller routing conflict, I had this issue after struggling for sometime I found this answer which has resolved the issue.
routes.IgnoreRoute("{allsvc}", new { allsvc = #"..svc(/.*)?" });

How to Call .NET AuthenticationService from json client without ASP.NET

I have a WCF 4 service which is in a Secure subfolder, accessible after the client has authenticated using Forms authentication using the .NET AuthenticationService.
This WCF service is for a mobile app client which communicates via json but is not an ASP.NET app. I have successfully configured the service to use json and the AuthenticationService has the standard configuration as documented in many places e.g. http://msdn.microsoft.com/en-us/library/bb398990.aspx
The docmentation for the AuthenticationService says "The application must be able to send and consume a SOAP message". However I want the client to be able to use json for authentication as well. Is this possible? What's the configuration required?
I found this article http://weblogs.asp.net/asptest/archive/2008/12/09/working-with-the-asp-net-ajax-authentication-service.aspx so it looks like the AuthenticationService can handle json but it uses Client Application Services. The mobile app client is not an ASP.NET app.
Yes the AuthenticationService can handle JSON. There are a couple of ways to do. Here is a sample configuration I've used in the past using the element.
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="System.Web.ApplicationServices.AuthenticationService" behaviorConfiguration="MyServiceBehavior">
<endpoint address="" behaviorConfiguration="ajaxBehavior"
contract="System.Web.ApplicationServices.AuthenticationService"
binding="webHttpBinding" bindingConfiguration="webHttpBindingSecure"
bindingNamespace="http://asp.net/ApplicationServices/v200"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="ajaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingSecure">
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
The question is old for long time but I think it will help someone if I post my answer.
For sure you can return json for AuthenticationService.
The solution is very simple like Garret answer, you only need configure another endpoint like this but you need add 2 addition attributes for endpoint behaviors: defaultOutgoingResponseFormat="Json" and defaultBodyStyle="Wrapped" to overwrite default soap response.
<system.serviceModel>
<services>
<service behaviorConfiguration="AuthenticationServiceBehaviors" name="System.Web.ApplicationServices.AuthenticationService">
<endpoint address="" behaviorConfiguration="ajaxBehavior"
contract="System.Web.ApplicationServices.AuthenticationService"
binding="webHttpBinding" bindingConfiguration="RestBinding"
bindingNamespace="http://asp.net/ApplicationServices/v200"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="RestBinding" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ajaxBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="AuthenticationServiceBehaviors">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
I hope this help someone who want to expose asp.net membership as json format to use in mobile app.

Equivalent web.config settings for WebServiceHostFactory

I'm having problems finding how to setup my web.config to use the same settings as using the WebServiceHostFactory on my RESTful WCF service. Does anyone know what the equivalent web.config would look like instead of using that factory, or how I can find it (assume I should be able to attach and find the endpoint objects etc?).
I need to change a couple of small things that the factory is using, and set the authentication to none, so it will play nicely with IIS (currently getting IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous' - and I cant change the IIS settings).
You should be able to add a reference to your service in the Web.config under the system.serviceModel section.
By specifying the full name of the service implementation as the name, of the service element you can then configure it to use specific end points and behaviours.
Hope this helps.
I have used a similar config to below for controlling my WCF Rest Services.
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<protocolMapping>
<add scheme="http" binding="httpBehavior"/>
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="serviceBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="{fullname of your service}">
<endpoint address="" behaviorConfiguration="httpCommerceBehavior" binding="webHttpBinding" bindingConfiguration="serviceBinding" contract="{Service Contract full name}>
</endpoint>
</service>
</services>
</system.serviceModel>

WCF SSL Rest based web service with basic authetication

I have a simple WCF REST based service deployed (development ofcourse) using SSL. I am trying to make it work with basic authentication but quite frankly am getting nowhere with it.
IIS 6.0
REST based - Using webHttpBinding
Here is what my web.config looks like ... just the relevant portions:
<system.serviceModel>
<services>
<service behaviorConfiguration="ThisTestService.MyTestServiceBehavior"
name="ThisTestService.MyTestService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="Secure" behaviorConfiguration="WebBehavior" contract="ThisTestService.IMyTestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration="Secure" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ThisTestService.MyTestServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false" 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>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="Secure">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
I have Anonymous authentication turned off in IIS on the virtual directory for the WCF service and Basic authentication is turned on.
When I try to access it say using https://localhost/ThisTestService/MyTestService.svc, I cannot get to it. It gives the "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].".
I've googled a lot but so far all my attempts to understand and fix the issue have been in vain. If I use anonymous authentication then I have no issues however I need to use basic authentication.
Any help is greatly appreciated. Thanks.
You need to turn on https for the virtual directory in which you are hosting the service. (As explained in the last para of this article: http://msdn.microsoft.com/en-us/library/aa751792.aspx)