Создание и использование пользовательских служб WCF, размещенных в SharePoint - PullRequest
0 голосов
/ 04 июня 2018

Я следовал этому руководству для развертывания пользовательского WCF: https://nikpatel.net/2012/02/29/step-by-step-building-custom-wcf-services-hosted-in-sharepoint-part-i/

И это сработало, но сейчас я пытаюсь развернуть его в моем текущем решении, когда я развернул свое решение sharepoint, у меня естьследующее сообщение об ошибке:

Тип 'Test.PS2010.WCF.PSIExtension.Service, Test.PS2010.WCF.PSIExtension, Version = 1.0.0.0, Culture = нейтральный, PublicKeyToken = 6e6682caac50df24', предоставляемый в качестве службыЗначение атрибута в директиве ServiceHost не может быть найдено.

Итак, в моем решении у меня есть PSIExtension (Test.PS2010.WCF.PSIExtension) и мое решение sharepoint (Test.PS2010.WCF), мой Psiextensionсодержит следующие файлы:

Файл веб-конфигурации:

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="extensionBasicHttpConf"
                 closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 allowCookies="true"
                 maxBufferSize="4194304"
                 maxReceivedMessageSize="500000000"
                 messageEncoding="Text"
                 transferMode="StreamedResponse">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm="" />
          </security>
        </binding>
        <binding name="mexHttpBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm="" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PSIExtensionServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Test.PS2010.WCF.PSIExtension.Service"
             behaviorConfiguration="PSIExtensionServiceBehavior">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="extensionBasicHttpConf"
                  contract="Test.PS2010.WCF.PSIExtension.IService" />
        <endpoint address="mex"
                  binding="basicHttpBinding"
                  bindingConfiguration="mexHttpBinding"
                  name="mex"
                  contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Мой файл Iservice.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Xml;

namespace Test.PS2010.WCF.PSIExtension
{

    [ServiceContract]
    internal interface IService
    {
        [OperationContract]
        bool isAlive(out string m_strError);
    }

}

и мой сервис:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.Web;
using System.Xml;
using System.Data;
using System.Reflection;
using System.Configuration;

namespace Test.PS2010.WCF.PSIExtension
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    public class Service : IService
    {
        private static HttpContext c_objContext;
        private static string l_strNameSpace;
        private static string l_strTypeName;

        public Service()
        {
            l_strNameSpace = this.GetType().Namespace;
            l_strTypeName = this.GetType().Name;
            c_objContext = HttpContext.Current;
        }

        public bool isAlive(out string m_strMessage)
        {
            m_strMessage = "Alive and Kicking ('" + getDbConnectionString() + "')";
            return (true);
        }
        private static Uri getServiceUri()
        {
            var l_objRequestUri = c_objContext.Request.Url;
            int l_intPortNum = 80;
            var l_objPortString = l_objRequestUri.GetComponents(UriComponents.Port, UriFormat.SafeUnescaped);

            if (!string.IsNullOrEmpty(l_objPortString))
            {
                l_intPortNum = int.Parse(l_objPortString);
            }
            var l_objUriBuilder = new UriBuilder(l_objRequestUri.GetComponents(UriComponents.Scheme, UriFormat.SafeUnescaped),
                                                 l_objRequestUri.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped),
                                                 l_intPortNum,
                                                 c_objContext.Request.RawUrl);
            return (l_objUriBuilder.Uri);
        }

        private static string getDbConnectionString()
        {
            string l_strUrl = null;

            try
            {
                l_strUrl = getServiceUri().ToString();
                l_strUrl = l_strUrl.Replace("http://", "");
                l_strUrl = l_strUrl.Replace("https://", "");
                l_strUrl = l_strUrl.Replace("/_vti_bin/psi/Test.PS2010.Fruit.PSIExtension.svc", "");

                return (ConfigurationManager.AppSettings[l_strUrl + "_PSCustom_ConnectionString"]);
            }
            catch (Exception e)
            {
                return (e.Message + " (" + l_strUrl + ")");
            }
        }
    }

}

и в моем решении sharepoint я имею в следующих папках ISAPI ==> PSI ==> Test.PS2010.WCF.PSIExtension.svc:

<%@ServiceHost language="c#" Service="Test.PS2010.WCF.PSIExtension.Service, Test.PS2010.WCF.PSIExtension, Version=1.0.0.0, Culture=neutral, PublicKeyToken=663d2f95b0755e1f" %>

Я не знаю, почему у меня этосообщение, я сделал некоторые поиски на досках, но я попробовал все таклозунги, которые предлагали люди, но в моем случае ничего не работает, есть идеи почему?

1 Ответ

0 голосов
/ 06 июня 2018

Я наконец нашел, где была проблема После проверки всех зависимостей, я посмотрел в свой sharepointPackage ==> Advance и здесь мне пришлось добавить свои dll-файлы, и теперь он работает

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...