Click here to Skip to main content
15,606,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi pleas help me

i have a project silverlight,wcf service

i 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 implements

this is code service:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceContract(Namespace = "")]
    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;

        #region connect

        public void Connect(string Ip, int Port)
                serverSend = new IPEndPoint(IPAddress.Parse(Ip), Port);
                SocketSender = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.Tcp);
                SocketSender.BeginConnect(serverSend,new AsyncCallback(ConnectCallBack),SocketSender);

        private void ConnectCallBack(IAsyncResult ar)
            Socket worker = (Socket)ar.AsyncState;
            Socket temp = worker;
                sbuffer = new byte[1024];
                sensor_connect = true;
                sbuffer = System.Text.UTF8Encoding.UTF8.GetBytes("Connect");
                temp.BeginSend(sbuffer, 0, sbuffer.Length, SocketFlags.None, new AsyncCallback(SenderCallBack),temp);
                sensor_connect = false;
                SocketAccept = new MySocket();
               // SocketAccept.socketOut =worker;


and this is webconfig:

  For more information on how to configure your ASP.NET application, please visit
    <!-- For more information on Entity Framework configuration, visit -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirepermission="false" />
    <add name="manomoshaverConnectionString" connectionstring="Data Source=.;Initial Catalog=manomoshaver;Integrated Security=True" providername="System.Data.SqlClient" />
    <compilation debug="true" targetframework="4.0" />
        <add name="silverlightFaults" type="prjManomoshaver.Web.SilverlightFaultBehavior, prjManomoshaver.Web" />
        <behavior name="SilverlightFaultBehavior">
          <!--<silverlightfaults />-->
        <behavior name="">
          <servicemetadata httpgetenabled="false" />
          <servicedebug includeexceptiondetailinfaults="true" />
        <binding name="prjManomoshaver.Web.DataService.customBinding0">
          <binarymessageencoding />
          <context />
          <httptransport />
    <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />
      <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" />
    <defaultconnectionfactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameter value="v11.0" />
Updated 17-Apr-13 12:37pm

The error message is quite clear: this is a straightforward requirement to your code: don't do such things.

Indeed, I have no idea what makes you System.Data.Services.IRequestHandler. I don't think you should even ask "why not"? Because this is not designed the way you might wrongfully imply. This is your who should understand why you are implementing this interface by a class marked with a [ServiceContract] attribute. Frankly, I don't even understand why would you mark with this attribute a type which is a class but not interface. Event though it actually could be a class (the attribute targets are Class or Interface), I would recommend to use interface. The intended usage pattern is shown in this article:[^].

See also:[^].

A couple of side notes:
  • What are you doing? Why would you use an empty string for a namespace, ever? Use the namespace. After all, you could just omit any positional parameters.
    Please see the class properties which could be used as named parameters, on the MSDN help page referenced above.
  • Even if you still need an empty string somewhere: for neat code and better maintenance, never use "", use string.Empty.

Share this answer
thank you very much...........
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900