Click here to Skip to main content
15,894,460 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:

C#
[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);
            }

        }




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>
Posted
Updated 17-Apr-13 12:37pm
v3

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: http://msdn.microsoft.com/en-us/library/ms733070.aspx[^].

See also: http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.aspx[^].

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.


—SA
 
Share this answer
 
v2
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