本文介绍了wcf - &gt;错误:ServiceContract并继承ServiceContract的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨请求帮助我 i有一个项目silverlight,wcf服务 i把它误认为:prjManom​​oshaver.Web.Service1类型的服务类都定义了一个ServiceContract,并从System.Data.Services.IRequestHandler类型继承了一个ServiceContract。合同继承只能在接口类型中使用。如果类使用ServiceContractAttribute标记,则它必须是具有ServiceContractAttribute的层次结构中的唯一类型。考虑将类型System.Data.Services.IRequestHandler上的ServiceContractAttribute移动到类型为System.Data.Services.IRequestHandler的单独接口上实现 这是代码服务: hipleas help mei have a project silverlight,wcf servicei take it error:The service class of type prjManomoshaver.Web.Service1 both defines a ServiceContract and inherits a ServiceContract from type System.Data.Services.IRequestHandler. Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. Consider moving the ServiceContractAttribute on type System.Data.Services.IRequestHandler to a separate interface that type System.Data.Services.IRequestHandler implementsthis is code service: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceContract(Namespace = "")] [ServiceBehaviorAttribute(InstanceContextMode=InstanceContextMode.PerCall)] public class Service1 : DataService<BankDataContext>,IRequestHandler { // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: config.UseVerboseErrors = true; config.SetEntitySetAccessRule("MySocket", EntitySetRights.All); config.SetServiceOperationAccessRule("Connect", ServiceOperationRights.All); config.SetServiceOperationAccessRule("Accept", ServiceOperationRights.All); config.SetServiceOperationAccessRule("Receive", ServiceOperationRights.All); config.SetServiceOperationAccessRule("Send", ServiceOperationRights.All); config.SetServiceOperationAccessRule("Close_Connect", ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } #region declare public string strReceive = ""; public static Socket SocketReceive = null; public static Socket SocketSender = null; byte[] buffer = null; byte[] sbuffer = null; IPEndPoint serverSend = null; IPEndPoint serverReceive = null; public bool sensor_connect=false; public bool sensor_send = false; public bool sensor_receive = false; public bool sensor_accept = false; MySocket SocketAccept = null; #endregion #region connect [OperationContract,WebGet] public void Connect(string Ip, int Port) { try { Close_Connect(null); serverSend = new IPEndPoint(IPAddress.Parse(Ip), Port); SocketSender = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp); SocketSender.BeginConnect(serverSend,new AsyncCallback(ConnectCallBack),SocketSender); } catch { Close_Connect(null); } } private void ConnectCallBack(IAsyncResult ar) { Socket worker = (Socket)ar.AsyncState; Socket temp = worker; try { sbuffer = new byte[1024]; worker.EndConnect(ar); sensor_connect = true; sbuffer = System.Text.UTF8Encoding.UTF8.GetBytes("Connect"); temp.BeginSend(sbuffer, 0, sbuffer.Length, SocketFlags.None, new AsyncCallback(SenderCallBack),temp); } catch { sensor_connect = false; SocketAccept = new MySocket(); // SocketAccept.socketOut =worker; Close_Connect(SocketAccept); } } ,这是webconfig: and this is webconfig:<!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --><configuration> <configsections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirepermission="false" /> </configsections> <connectionstrings> <add name="manomoshaverConnectionString" connectionstring="Data Source=.;Initial Catalog=manomoshaver;Integrated Security=True" providername="System.Data.SqlClient" /> </connectionstrings> <system.web> <compilation debug="true" targetframework="4.0" /> </system.web> <system.servicemodel> <extensions> <behaviorextensions> <add name="silverlightFaults" type="prjManomoshaver.Web.SilverlightFaultBehavior, prjManomoshaver.Web" /> </behaviorextensions> </extensions> <behaviors> <endpointbehaviors> <behavior name="SilverlightFaultBehavior"> <!--<silverlightfaults />--> </behavior> </endpointbehaviors> <servicebehaviors> <behavior name=""> <servicemetadata httpgetenabled="false" /> <servicedebug includeexceptiondetailinfaults="true" /> </behavior> </servicebehaviors> </behaviors> <bindings> <custombinding> <binding name="prjManomoshaver.Web.DataService.customBinding0"> <binarymessageencoding /> <context /> <httptransport /> </binding> </custombinding> </bindings> <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" /> <services> <service name="prjManomoshaver.Web.DataService"> <endpoint address="" binding="customBinding" bindingconfiguration="prjManomoshaver.Web.DataService.customBinding0" name="prjManomoshaver.Web.DataService.customBinding0" contract="prjManomoshaver.Web.DataService" behaviorconfiguration="SilverlightFaultBehavior" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.servicemodel> <entityframework> <defaultconnectionfactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultconnectionfactory> </entityframework></configuration> 推荐答案 这篇关于wcf - &gt;错误:ServiceContract并继承ServiceContract的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 00:11