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
bool AddExam(...)
despite having others exposed from the service side!
Here are my contracts:
IUser.cs
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
using System;
...
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
using System;
...
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
using System;
...
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
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
{
[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),
="1.0"="utf-8"
<configuration>
<configSections>
<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>
<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>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<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:
="1.0"="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.