Skip to content

CreateUnAuthenticatedWebService

Kyryl Krylov, CPA edited this page Dec 5, 2020 · 6 revisions

How to create UnAuthenticated webService

Create CS class
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using Terrasoft.Core;
using Terrasoft.Web.Common;
using System.Runtime.Serialization;

namespace TrainingClio
{
	[ServiceContract]
	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
	public class CreatioWsTemplate : BaseService
	{
		#region Methods : REST
		[OperationContract]
		[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, 
			BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
		public string GetMethodname(string name)
		{
			return "Ok "+name;
		}
		#endregion
	}
}
Register WCF Service
Create new file with svc extension in [AppPath]\Terrasoft.WebApp\ServiceModel In this example I've created KirillCustomService.svc with the following content, where TrainingClio is the namespace of my WebService handler, and CreatioWsTemplate is the class name of the handler.
<%@ ServiceHost Language="C#" Debug="true" Service="TrainingClio.CreatioWsTemplate" %>
Configure WCF Service
Open [AppPath]\Terrasoft.WebApp\ServiceModel\http\services.config and add the following content. GetMethodname is the method that will be called when service is executed.

servicesConfig

<service name="TrainingClio.CreatioWsTemplate">
    <endpoint name="GetMethodname"
        address=""
        binding="webHttpBinding"
        behaviorConfiguration="RestServiceBehavior"
        bindingNamespace="http://Terrasoft.WebApp.ServiceModel"
        contract="TrainingClio.CreatioWsTemplate" />
</service>CreatioWsTemplate" %>
Configure Access Permission
Open [AppPath]\Terrasoft.WebApp\web.config and add the following

webConfig

<location path="ServiceModel/KirillCustomService.svc">
<system.web>
    <authorization>
    <allow users="*" />
    </authorization>
</system.web>
</location>

then find "AllowedLocations" key and append the ServiceModel/KirillCustomService.svc to the end of the line. Here is an example of Studio product ver 7.17.0.2164

<add key="AllowedLocations" value="ServiceModel/MsgUtilService.svc;Nui/Feedback.aspx;Nui/UserManagement.aspx;ServiceModel/GeneratedWebFormService.svc;ServiceModel/ExchangeListenerService.svc;ServiceModel/IndexingConfigService.svc;ServiceModel/ReportCallbackService.svc;TestTools/Tests.aspx;TestTools/Tests.Debug.aspx;TestTools/Tests.Release.aspx;ServiceModel/TestDataService.svc;ServiceModel/CaseRatingManagementService.svc;ServiceModel/MandrillService.svc;ServiceModel/EventTrackingService.svc;TestTools/UnitTests.aspx;ServiceModel/ScoringService.svc;ServiceModel/CESWebHooksService.svc;ServiceModel/CESTroubleshootingService.svc;ServiceModel/GeneratedObjectWebFormService.svc;ServiceModel/BsoJivosite.svc;ServiceModel/BsoTilda.svc;ServiceModel/DocumentsService.svc;ServiceModel/PtOauthService.svc;ServiceModel/AletMangoCloudConnector.svc;ServiceModel/ScriptDesignerService.svc;ServiceModel/FacebookWebhookService.svc;Features.aspx;ServiceModel/OpChatraWebhook.svc;ServiceModel/OPMyCallsUtils.svc;/ServiceModel/ServiceOAuthAuthenticatorEndpoint.svc;ServiceModel/MobileMetadataService.svc;ServiceModel/OmnichannelMessagingService.svc;ServiceModel/FacebookOmnichannelMessagingService.svc;ServiceModel/TrcEmailTrackingService.svc;ServiceModel/TrcEmailTrackingService.svc;ServiceModel/KirillCustomService.svc" />

Try calling your service http://k_krylov:8010/0/ServiceModel/KirillCustomService.svc/GetMethodname?name=Kirill

Clone this wiki locally