Здравствуйте, коллеги.
Пытаюсь построить сервис, который закрывает обращение и дает возможность добавлять комментарии при закрытии.
Скелет класса CaseRatingService
(клон CaseRatingManagementService
):
{
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using System.ServiceModel.Channels;
using System.Security.Principal;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Terrasoft.Common;
using Terrasoft.Common.Json;
using Terrasoft.Core;
using Terrasoft.Core.DB;
using Terrasoft.Core.Entities;
using Terrasoft.Core.Store;
using Terrasoft.Nui.ServiceModel;
using Terrasoft.Nui.ServiceModel.Extensions;
using Terrasoft.UI.WebControls;
#region Class: CaseManagementService
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CaseManagementService {
[OperationContract]
[WebGet(UriTemplate = "Case/{id}/{rating}")]
public void GetCase(string id, string rating) {
var context = HttpContext.Current;
try{
HttpRequest request = context.Request;
if (id == null || rating == null) {
throw new ArgumentNullOrEmptyException("rating");
}
_appConnection = HttpContext.Current.Application["AppConnection"] as AppConnection;
_sysUserName = _appConnection.SystemUserConnection.CurrentUser.Name;
_sessionId = Guid.NewGuid().ToString("N");
Thread.CurrentPrincipal = new TerrasoftPrincipal(new GenericIdentity(_sysUserName), new string[0], _sessionId);
this._setResponseText(context.Response, "Ok");
} catch (Exception ex) {
this._setResponseText(context.Response, ex.Message);
}
}
#region Fields: Private
private UserConnection _userConnection;
private string _sessionId;
private string _sysUserName;
private AppConnection _appConnection;
#endregion
#region Private property: UserConnection::UserConnection
private UserConnection UserConnection {
get {
if (_userConnection != null) {
return _userConnection;
}
if (HttpContext.Current.Session != null) {
_userConnection = HttpContext.Current.Session["UserConnection"] as UserConnection;
}
if (_userConnection == null) {
var result = new UserConnection(_appConnection);
result.Initialize();
result.SessionId = _sessionId;
_userConnection = result;
}
return _userConnection;
}
}
#endregion
#region Private method: _setResponseText(response,text)::void
private void _setResponseText(HttpResponse response, string text) {
var label = string.Format("{0}",
text);
response.Write(label);
}
#endregion
}
#endregion
}
Выдает такую ошибку:
Date (UTC): 08.12.2016 9:27:01
Exception Message: Не удалось найти тип "Terrasoft.Configuration.CaseManagementService.CaseManagementService", заданный значением атрибута Service в директиве ServiceHost или указанный в элементе конфигурации system.serviceModel/serviceHostingEnvironment/serviceActivations.
Exception Type: System.InvalidOperationException
Exception Source: System.ServiceModel.Activation
Exception Stack Trace:
в System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
в System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
в System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
в System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
SessionID: 1r4srdi5za0yv132xnjywfzg
Request URL: /WebApp770/0/ServiceModel/CaseManagementService.svc
Request Path: /WebApp770/0/ServiceModel/CaseManagementService.svc
Request Type: GET
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
User Host Address: ::1
User: EFrolov
Is Authenticated: True
Authentication Type: Forms
Is Secure Connection: False
Application Version: 7.7.0.0
Application Path: G:\Projects\Core\TSBpm\Src\Lib\Terrasoft.WebApp.Loader\Terrasoft.WebApp\
Application Virtual Path: /WebApp770/0
Application Trust Level: Full
Machine Name: PC-23-N
Is Local: True
Process ID: 10396
Process Name: iisexpress.exe
Process Account Name: INDOORMEDIA\developer
Thread Account Name: INDOORMEDIA\developer
OS Version: Microsoft Windows NT 6.2.9200.0
Net Framework Version: 4.0.30319.42000
DBExecutor Type: MSSqlExecuto
1. в ServiceModel поцепил файлик CaseManagementService.svc
:
2. в services.config
(http и https) :
address=""
binding="webHttpBinding"
behaviorConfiguration="RestServiceBehavior"
bindingNamespace="http://Terrasoft.WebApp.ServiceModel"
contract="Terrasoft.Configuration.CaseManagementService.CaseManagementService" />
3. в web.config
:
...
...
4. в App.config
:
...
Нравится
Вопрос закрыт.
Совет на будущее:
"ПРОВЕРЯЙТЕ КОНФИГУРАЦИЮ, НА КОТОРОЙ ВС СОЗДАВАЛСЯ И ПОД КАКОЙ ВЫ К НЕМУ СТУЧИТЕСЬ!"
Добрый день!
Имеется следующий пример реализации.
В конфигурации необходимо создать схему исходного кода c контрактом сервиса:
[ServiceContract]
public interface IService
{
[OperationContract]
SPMClientInfoResponse SPMClientInfo(string Login);
}
[DataContract]
public class SPMClientInfoResponse
{
bool success = true;
string errorText = "";
[DataMember]
public bool Success
{
get { return success; }
set { success = value; }
}
[DataMember]
public string ErrorText
{
get { return errorText; }
set { errorText = value; }
}
}
и схему исходного кода c реализацией сервиса:
public class SPMSUBPService : IService
{
public SPMClientInfoResponse SPMClientInfo(string Login)
{
return new SPMClientInfoResponse();
}
}
Методы конфигурационного веб-сервиса должны быть помечены атрибутами [OperationContract] и
[WebInvoke] с параметрами.
Например, вот так: [OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle
= WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
Далее, в папке В папке Terrasoft.WebApp\ServiceModel создаем файл CaseManagementService.svc с примерно таким текстом:
<%@ ServiceHost Language="C#" Debug="true" Service="CaseManagementService.CaseManagementService" Factory="System.ServiceModel.Activation.ServiceHostFactory" %>
Добавить в файл Terrasoft.WebApp\ServiceModel\http\services.config описание сервиса:
...
...
Модифицировать Terrasoft.WebApp\Web.config