Публикация

Веб-сервис без авторизации для вызова БП (Бизнесс процесса) с параметрами

Вопрос

Веб-сервис без авторизации для вызова БП (Бизнесс процесса) с параметрами.

Ответ

Инструкция по написанию сервиса, вызывающего БП, доступного по HTTP\GET с передачей параметров в БП:  https://community.terrasoft.ru/articles/veb-servis-dostupnyi-bez-avtorizacii-cors

Сервис:

namespace Terrasoft.Configuration
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Linq;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.ServiceModel.Activation;
    using System.Web;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Drawing;
    using System.Globalization;
    using System.Net;
    using System.Text;
    using System.IO;
 
    using Terrasoft.Core;
    using Terrasoft.Core.Configuration;
    using Terrasoft.Core.DB;
    using Terrasoft.Core.Entities;
    using Terrasoft.Core.Process;
    using Terrasoft.Web.Common;
    using Terrasoft.Common;
    using Terrasoft.Common.Json;
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class UsrLaunchProccService : BaseService
    {
        private UserConnection SystemUserConnection {
            get {
                return AppConnection.SystemUserConnection;
            }
        }
 
        public ProcessSchemaManager ProcessSchemaManager {
            get {
                return (ProcessSchemaManager)SystemUserConnection.GetSchemaManager("ProcessSchemaManager");
            }
        }
 
        [OperationContract]
        [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped,
        ResponseFormat = WebMessageFormat.Json, UriTemplate = "runUsrTestProcc/{ustTestPhone}/")]
        public string runUsrTestProcc(string ustTestPhone)
        {
            ///////
            var currentWebOperationContext = WebOperationContext.Current;
            var outgoingResponseHeaders = currentWebOperationContext.OutgoingResponse.Headers;
            var incomingRequestOrigin = currentWebOperationContext.IncomingRequest.Headers["Origin"];
            outgoingResponseHeaders.Add("Access-Control-Allow-Origin", incomingRequestOrigin);
            ///////
            var result = "";
            try {
                var UserConnection = this.SystemUserConnection;
 
                var manager = UserConnection.ProcessSchemaManager;
                var processSchema = manager.GetInstanceByName("UsrTestProcc");
                var process = processSchema.CreateProcess(UserConnection);
                if (processSchema.Parameters.ExistsByName("UstTestPhone"))
                {
                process.SetPropertyValue("UstTestPhone", ustTestPhone);
                }
                process.Execute(UserConnection);
                result = "OK for ustTestPhone = " + ustTestPhone;
            } catch (Exception ex) {
                result = ex.Message;
            };
            return result;
        }
 
 
        [OperationContract]
        [WebInvoke(Method = "OPTIONS", UriTemplate = "*")]
        public void GetWebFormLeadDataRequestOptions() {
            var outgoingResponseHeaders = WebOperationContext.Current.OutgoingResponse.Headers;
            outgoingResponseHeaders.Add("Access-Control-Allow-Origin", "*");
            outgoingResponseHeaders.Add("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
            outgoingResponseHeaders.Add("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, X-Requested-With, X-Requested-With, x-request-source");
            outgoingResponseHeaders.Add("Access-Control-Request-Headers", "X-Requested-With, x-request-source, accept, content-type");
        }
    }
}

 

Нравится

Поделиться

0 комментариев
Показать все комментарии