我创建了一个名为“ TPUSRER”的asp.net Web应用程序,并在其中添加了WCF服务,该服务实现了一个共享点在线远程事件接收器,这是我的代码:-
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=\"Web\" /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时出现此错误:-
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
那么有人可以对此错误提出建议吗? 谢谢
答案 0 :(得分:1)
该错误表示您的类Service1
应该实现您的接口IService1
。您可以实现多个接口。
public class Service1 : IService1, IRemoteEventService
或者您的界面可以扩展IRemoteEventService
,然后可以在ProcessEvent()
中实现DoWork()
和Service1
。
[ServiceContract]
public interface IService1 : IRemoteEventService