构建和使用托管在SharePoint中的自定义WCF服务

时间:2018-06-04 11:59:51

标签: wcf sharepoint

我按照本教程部署了自定义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 = neutral,PublicKeyToken = 6e6682caac50df24',作为ServiceHost指令中的Service属性值提供找不到。

所以在我的解决方案中,我有我的PSIExtension(Test.PS2010.WCF.PSIExtension)和我的sharepoint Solution(Test.PS2010.WCF),我的Psiextension包含以下文件:

webconfig文件:

<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 ==&gt; PSI ==&gt; 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 :(得分:0)

我终于找到了问题所在 检查完所有的家属后,我查看了我的sharepointPackage ==&gt;预先 在这里我必须添加我的DLL文件,现在它正在工作