Название контракта TPUSRER.IService1 не найдено в списке контрактов, реализованных сервисом Service1. - PullRequest
0 голосов
/ 11 февраля 2020

Я создал asp. net веб-приложение с именем "TPUSRER", и внутри него я добавил службу WCF, которая реализует удаленный приемник событий sharepoint, вот мой код: -

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

namespace TPUSRER
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void DoWork();
    }
}

и сервис: -

namespace TPUSRER
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RER" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select RER.svc or RER.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IRemoteEventService
    {
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
//code goes here

вот мой web.config: -

<?xml version="1.0" encoding="utf-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <customErrors mode = "Off"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

  <system.serviceModel>
    <services>
      <service name="TPUSRER.Service1" behaviorConfiguration="WCF.ServiceBehavior" >
        <endpoint address=""
              binding="webHttpBinding"
              bindingConfiguration="NoSecurityHttpBinding"
              contract="TPUSRER.IService1" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WCF.ServiceBehavior">
          <serviceMetadata  httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior >
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="NoSecurityHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>
  <appSettings file="custom.config">
    <add key="ClientId" value="***" />
    <add key="ClientSecret" value="****=" />
  </appSettings>
</configuration>

но когда я развернул этот WCF внутри azure, я получил эту ошибку: -

Server Error in '/' Application.
The contract name 'TPUSRER.IService1' could not be found in the list of contracts implemented by the service 'Service1'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The contract name 'TPUSRER.IService1' could not be found in the list of contracts implemented by the service 'Service1'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: The contract name 'TPUSRER.IService1' could not be found in the list of contracts implemented by the service 'Service1'.]
   System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName) +13095324
   System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress, Boolean skipHost) +13094015
   System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection) +69
   System.ServiceModel.ServiceHostBase.ApplyConfiguration() +178
   System.ServiceModel.ServiceHost.ApplyConfiguration() +61
   System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +184
   System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses) +46
   System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +146
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +32
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +524
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +1421
   System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +641

[ServiceActivationException: The service '/service1.svc' cannot be activated due to an exception during compilation.  The exception message is: The contract name 'TPUSRER.IService1' could not be found in the list of contracts implemented by the service 'Service1'..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +500298
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
   System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +351498
   System.Web.<>c__DisplayClass11_0.<InvokeEndHandler>b__0() +34
   System.Web.StepInvoker.Invoke(Action executionStep) +101
   System.Web.<>c__DisplayClass4_0.<Invoke>b__0() +22
   Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.OnExecuteRequestStep(HttpContextBase context, Action step) +64
   System.Web.<>c__DisplayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction) +54
   System.Web.StepInvoker.Invoke(Action executionStep) +85
   System.Web.AsyncEventExecutionStep.InvokeEndHandler(IAsyncResult ar) +114
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +9898128

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3535.0

Так может кто-нибудь дать совет по этой ошибке? Спасибо

1 Ответ

1 голос
/ 11 февраля 2020

Ошибка означает, что ваш класс Service1 должен реализовать ваш интерфейс IService1. Вы можете реализовать несколько интерфейсов.

public class Service1 : IService1, IRemoteEventService

Или ваш интерфейс может расширяться IRemoteEventService, тогда вы можете реализовать ProcessEvent() и DoWork() в Service1.

[ServiceContract]
public interface IService1 : IRemoteEventService
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...