Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.

I created a WCF library project. I have tested it n the WCF Test Client and everything works just as expected.

When I add the service as a service reference for a Windows Form client, for some unknown reason, I can only get one Operation Contract (defined in IExam.cs called
C#
bool AddExam(...) 
despite having others exposed from the service side!

Here are my contracts:

IUser.cs

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

namespace Examination
{

    [ServiceContract]
    public interface IUser
    {
        [OperationContract]
        bool Login(string userName, string passWord);
        [OperationContract]
        List<User> GetUsers();
    }

    [DataContract]
    public class UserData
    {
        [DataMember]
        public string UserName;

        [DataMember]
        public string password;
    }


}


IExam.cs

C#
using System;
... //Just as before.

namespace Examination
{
    [ServiceContract]
    public interface IExam
    {
        [OperationContract]
        bool AddExam(string unitCode, string unitName, String examDate, double duration,
            string instructions, string university, string course, int userID);
    }

    [DataContract]
    public class ExamData
    {
        [DataMember]
        public int ExamID;

        [DataMember]
        public string UnitCode;

        [DataMember]
        public string UnitName;

        [DataMember]
        public string ExamDate;

        [DataMember]
        public double Duration;

        [DataMember]
        public string Instructions;

        [DataMember]
        public string University;

        [DataMember]
        public string Course;

        [DataMember]
        public int UserID;
    }
}


ISection.cs


C#
using System;
... //Just as before.

namespace Examination
{
    [ServiceContract]
    public interface ISection
    {
        [OperationContract]
        bool AddSection(string sectionName,int marks, int examId);

        List<Section> GetSections();

    }

    [DataContract]
    public class SectionData
    {
        [DataMember]
        public int SectionID;

        [DataMember]
        public string SectionName;


        [DataMember]
        public int Marks;

        [DataMember]
        public int ExamId;

    }
}


IQuestion.cs

C#
using System;
... //Just as before.

namespace Examination
{
    [ServiceContract]
    public interface IQuestion
    {
        [OperationContract]
        bool AddQuestion(string questionPhrase, byte[] diagram, int marks, int sectionId, string answerPhrase, byte[] answerDiagram);

        [OperationContract]
        List<Question> GetQuestions();
    }

    [DataContract]
    public class QuestionData
    {
        [DataMember]
        public string QuestionPhrase;
        [DataMember]
        public byte[] QuestionDiagram;

        [DataMember]
        public int Marks;

    }
    [DataContract]
    public class Answer
    {
        [DataMember]
        public string AnswerPhrase;
        [DataMember]
        public byte[] AnswerDiagram;
    }
}


Service.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.ServiceModel;
using System.Text;


namespace Examination
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class Service : IUser, IExam, ISection, IQuestion
    {

        public bool Login(string userName, string password)
        {
           ...
        }

        private UserData GetUserData(string userName)
        {
            ...
        }

        public bool AddExam(string unitCode, string unitName, string examDate, double duration, string instructions, string university, string course, int userID)
        {
           ...
        }



        private ExamData GetExamData(string unitCode)
        {
            ...

        }


        public bool AddSection(string sectionName, int marks, int examId)
        {
            ...
        }

        

        public bool AddQuestion(string questionPhrase, byte[] questionDiagram, int marks, int sectionId, string answerPhrase, byte[] answerDiagram)
        {
            ...
        }


        public List<Exam> GetExams()
        {
            ...
        }


        public List<User> GetUsers()
        {
            ...
        }


        public List<Section> GetSections()
        {
            ...
        }


        public List<Question> GetQuestions()
        {
            ...
        }
    }
}


In the App.config (on the server side),

XML
<?xml version="1.0" encoding="utf-8"?>
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="Examination.Service">
        <endpoint address="" binding="basicHttpBinding" contract="Examination.IUser">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="session" binding="wsHttpBinding" bindingConfiguration=""
          contract="Examination.IExam" />
        <endpoint address="session" binding="wsHttpBinding" bindingConfiguration=""
          contract="Examination.ISection" />
        <endpoint address="session" binding="wsHttpBinding" bindingConfiguration=""
          contract="Examination.IQuestion" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/ExamGeneratorServices/Service/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="ExamDBContext" connectionString="metadata=res://*/ExamDatabase.csdl|res://*/ExamDatabase.ssdl|res://*/ExamDatabase.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\v11.0;initial catalog=ExamGenerator;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>


In the client's App.config, I have:

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IUser" />
            </basicHttpBinding>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IExam" />
                <binding name="WSHttpBinding_ISection" />
                <binding name="WSHttpBinding_IQuestion" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8733/Design_Time_Addresses/ExamGeneratorServices/Service/"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUser"
                contract="ExamServiceReference.IUser" name="BasicHttpBinding_IUser" />
            <endpoint address="http://localhost:8733/Design_Time_Addresses/ExamGeneratorServices/Service/session"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IExam"
                contract="ExamServiceReference.IExam" name="WSHttpBinding_IExam">
                <identity>
                    <userPrincipalName value="CHARLES\Charles" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:8733/Design_Time_Addresses/ExamGeneratorServices/Service/session"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISection"
                contract="ExamServiceReference.ISection" name="WSHttpBinding_ISection">
                <identity>
                    <userPrincipalName value="CHARLES\Charles" />
                </identity>
            </endpoint>
            <endpoint address="http://localhost:8733/Design_Time_Addresses/ExamGeneratorServices/Service/session"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IQuestion"
                contract="ExamServiceReference.IQuestion" name="WSHttpBinding_IQuestion">
                <identity>
                    <userPrincipalName value="CHARLES\Charles" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>


And when I create the proxy to start calling the Operation Contracts, I can only get

the Operation Contract defined:

bool AddExam(...);

Why are others not available on the client side and what can I do to make them available? I am totally stuck here. Please help me. I have looked through the internet for a solution for this but I just can't find any.
Posted
Comments
Krunal Rohit 18-Feb-14 10:26am    
Have you tried on WCF Test Client first ?
Wamuti 19-Feb-14 1:46am    
Yes I have and it works just as I expect it to. This is what makes it even more frustrating.
Krunal Rohit 19-Feb-14 10:01am    
Try to delete the web.config file on client side and update the service reference,
-KR

1 solution

you are moving on the right path, you just need to care of the following steps :

1- Make all the methods 'public' for example your method


C#
private UserData GetUserData(string userName)
       {
           ...
       }


is a private method which means you wont be able to access from outside the class.

2- Make sure all operation contracts of your methods are implemented inside the interface class of the service not outside it.

make sure to browse the service file itself 'service.SVC' and make sure that all your methods are there in the XML of it.
 
Share this answer
 
Comments
Krunal Rohit 18-Feb-14 10:25am    
All the interfaces are public, so there's no need to explicitly define all the methods as public.
-KR
Wamuti 19-Feb-14 6:07am    
Even so, I still got lots of public interfaces that would be available... However, even making them public still does not solve the problem.

Also, all contracts are inside the interface class respectively as shown in the code listings..

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