How to host WCF if contracts,implementation and host are separate assembly - asp.net

I have downloaded a layered sample from Codeplex from this link: https://layersample.codeplex.com/releases/view/107797
This contain a WCF service with this structure:
service contract library
service implementation library
web host project
Question: in the web host project, there is no .SVC file and it only contains configuration in the web.config file.
Can anyone guide me how it works or how I could consume/add service reference in a client application/how to host this on IIS.
This is the web.config file :
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./LeaveService.svc"
service="LeaveSample.Services.LeaveService" />
<add factory="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory"
relativeAddress="./LeaveWorkflowService.svc"
service="LeaveSample.Workflows.LeaveWorkflowService" />
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="LeaveSample.Services.LeaveService"
behaviorConfiguration="DefaultServiceBehavior">
<endpoint name="basicHttpLeaveService"
address=""
binding="basicHttpBinding"
contract="LeaveSample.Services.Contracts.ILeaveService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="LeaveWorkflowService">
<endpoint name="basicHttpWorkflowService"
address=""
binding="basicHttpBinding"
contract="ILeaveWorkflowService" />
<endpoint
address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<sqlWorkflowInstanceStore connectionStringName="workflowStore"
hostLockRenewalPeriod="00:00:30"
runnableInstancesDetectionPeriod="00:00:05"
instanceCompletionAction="DeleteAll"
instanceLockedExceptionAction="AggressiveRetry"
instanceEncodingOption="GZip" />
<workflowUnhandledException action="Cancel"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions></behaviorExtensions>
</extensions>
<tracking>
<profiles></profiles>
</tracking>
</system.serviceModel>
Thank you

The project you downloaded is using "fileless activation":
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./LeaveService.svc"
service="LeaveSample.Services.LeaveService" />
<add factory="System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory"
relativeAddress="./LeaveWorkflowService.svc"
service="LeaveSample.Workflows.LeaveWorkflowService" />
</serviceActivations>
The above portion of the configuration file defines two service activation endpoints, without having to have a physical .svc file.
It is hosted and consumed like any other WCF service using IIS - the only difference is there is no .svc file.
File-less activation was one of several WCF features introduced with WCF 4.0. You can read about it (and the other features) here - A Developer's Introduction to to Windows Communication Foundation 4.

Related

WCF Services - Configuration web service binding exception

All,
Env:
Asp.net 4.0
IIS 7 (or greater)
WCF service consumed by SL component
Authentication:
Anonymous/Forms
When I attempt to browse to my WCF web service (using browser) I get the following exception on my web service, I need to get rid of this error:
The authentication schemes configured on the host ('IntegratedWindowsAuthentication') do not allow those configured on the binding 'BasicHttpBinding' ('Anonymous'). Please ensure that the SecurityMode is set to Transport or TransportCredentialOnly. Additionally, this may be resolved by changing the authentication schemes for this application through the IIS management tool, through the ServiceHost.Authentication.AuthenticationSchemes property, in the application configuration file at the element, by updating the ClientCredentialType property on the binding, or by adjusting the AuthenticationScheme property on the HttpTransportBindingElement.
I looked at ALL related posts and none of them help me.
I am not using any authentication or user/pwd transmission for my service.
The service I need to get working is consumed by Silverlight component and has this name in web.config file:
Htmls.WebStore.Services.WebStoreServices (ignore the other service).
Here's my web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WebStoreServices_InsecureTransport" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="4096" />
<security mode="None" />
</binding>
<binding name="basicHttpBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="SitefinityWebApp.Sitefinity.Services.Content.EventsAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="EndpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="Telerik.Sitefinity.Web.Services.LocalizationBehavior" />
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Htmls.WebStore.Services.WebStoreServices">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="WebStoreServices_InsecureTransport" contract="Htmls.WebStore.Services.IWebStoreServices" />
</service>
<service name="SitefinityWebApp.Sitefinity.Services.Content.Events">
<endpoint address="" behaviorConfiguration="SitefinityWebApp.Sitefinity.Services.Content.EventsAspNetAjaxBehavior" binding="webHttpBinding" contract="SitefinityWebApp.Sitefinity.Services.Content.Events" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
The exception was caused by having incorrect permission on the folder where the xxxxx.svc file was. The folder was locked down using security permissions.

WCF: Moving from development to production website

I've got an ASP.NET website on my development server (test2.com) that contains two WCF services that are set up in their own IIS application in a subdirectory of that site (test2.com/services). Everything is working on this site as it should. I'm now ready to move this website and the services to my production server (test.com and test.com/services), and I'm continually getting an HTTP 400 message no matter what I try. I've updated the service references on the production website and renamed the appropriate references on the services to point to the production URL. I've also made the appropriate updates in my client web.config file to the following:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IChatService" />
<binding name="BasicHttpBinding_IOnlineUsersService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://test.com/services/ChatService.svc/services/chatservice.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IChatService"
contract="Chat.IChatService" name="BasicHttpBinding_IChatService" />
<endpoint address="http://test.com/services/OnlineUsersService.svc/services/onlineusersservice.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IOnlineUsersService"
contract="OnlineUsers.IOnlineUsersService" name="BasicHttpBinding_IOnlineUsersService" />
</client>
</system.serviceModel>
The appropriate web.config file on the service contains the following:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="ChatServiceLibrary.ChatService">
<endpoint address="/services/chatservice.svc" binding="basicHttpBinding" contract="ChatServiceLibrary.IChatService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="ChatServiceLibrary.OnlineUsersService">
<endpoint address="/services/onlineusersservice.svc" binding="basicHttpBinding" contract="ChatServiceLibrary.IOnlineUsersService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The web services themselves work fine if I call them from a web browser. What am I missing?

Why doesn't my serviceAuthenticationManagerType get called for basic authentication?

I am working with WCF OData Services and trying to use basic authentication. When I browse to my OData Services in a web browser I get the username/password prompt. But when I enter a user name and password my custom serviceAuthenticationManagerType does not get called and the login fails. Do I have something configured wrong?
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="basicHttp">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="dataServiceBehavior">
<!-- 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="true" />
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="WcfResearch.AuthorizationManagers.WcfResearchAuthorizationPolicy, WcfResearch.AuthorizationManagers" />
</authorizationPolicies>
</serviceAuthorization>
<serviceAuthenticationManager authenticationSchemes="Basic" serviceAuthenticationManagerType="WcfResearch.AuthorizationManagers.WcfResearchAuthenticationManager, WcfResearch.AuthorizationManagers"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="WcfResearch.WcfDataService1" behaviorConfiguration="dataServiceBehavior">
<endpoint binding="webHttpBinding" bindingConfiguration="basicHttp" contract="System.Data.Services.IRequestHandler" />
</service>
</services>

WCF: Updating Service Reference

I have an issue with updating (also tried deleting and adding) service reference of a modified WCF service in ASP.NET website project using "Add Service Reference" feature provided by VS 2010. It doesn't create the Reference.cs properly as it used to before changes. I verified my service configuration in the web.config, the endpoint seems to be properly configured with mexhttpbinding.
<service behaviorConfiguration="ServiceBehavior" name="Services.XyzService">
<endpoint address="" binding="wsHttpBinding" contract="Services.IXyzService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
Svc file also seems to be ok!!
<%# ServiceHost Language="C#" Debug="true" Service="Services.XyzService"%>
Any idea?

Unable to Connect to WCF Service from MVC Site

I've written a WCF service that is hosted within a Windows Service on my home computer. I then wrote an MVC3 site that is attempting to connect to the service. The MVC3 site is hosted on godaddy servers. I opened the ports on my firewall correctly because I am able to access the service description site from a computer on a different network, and I even had a friend connect to the web service from a console app running on his computer, and it worked perfectly. However, when I attempt to call the web service from my MVC3 site it throws the following error:
There was no endpoint listening at http://myExternIpAddress:8000/MyService/service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Here is the important part of the app.config for the service:
<services>
<service name="MyService.MyService"
behaviorConfiguration="MyServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/MyService/service" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="MyService.IMyService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
and here is the service section of the web.config for the MVC3 site
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myExternalIpAddress:8000/MyService/service"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
contract="LocalService.IMyService" name="BasicHttpBinding_IMyService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thanks for any help that you can provide!
I would contact GoDaddy for support. If the WCF service works from your friends machine - it is likely a hosting environment issue.

Resources