i used app.config file for self service host my code is as the following
using
System;using
System.Collections.Generic;using
System.Text;using
System.ServiceModel;using
System.Runtime.Serialization;using
System.Collections.Generic;using
System.Text;using
System.Collections;using
System.ComponentModel;using
System.Data;using
System.Threading;using
System.Xml;using
DBManager;using
Microsoft.Win32;using
System.Configuration;using
System.ServiceModel.Description;using
System.ServiceModel.Channels;
namespace
ServiceSide{
// Define a service contract.[
ServiceContract(Namespace = "ServiceSide")] public interface IVigUserServerEx{
[
OperationContract] bool LogIn(string strUserName, string strPassword);[
OperationContract] bool LogOff();[
OperationContract] void ReadServerXmlFile();[
OperationContract] void GetXmlFileName(ref string strXmlFileName);[
OperationContract] void FillServersNameDataMap(ArrayList arrAttributesServer);[
OperationContract] void GetServersNameDataMap(ref Hashtable ServerDataMap);}
public class VigUserServerData : IVigUserServerEx{
#region
define[
DataMember] private const int TIMEOUT = 1500;[
DataMember] private const string SERVER_LIST_FILE_NAME = "\\Servers.xml";[
DataMember] private const string REG_APP_KEY_NAME = "SOFTWARE\\Adyoron\\Viewstation\\5.00";#endregion
enum eServerMap{
eSERVER_NAME =
0,eMEDIAHOSTNAME,
eSQL_HOST_NAME,
eMEDIA_PATH,
eMEDIA_DB_NAME,
eAUDIT_DB_NAME,
eNUM_OF_ATTRIBUTES
};
public struct MediaServer{
public string strServerName; public string strMediaHostName; public string strMediaPath; public string strDBName; public string strAuditDBName;}
[
DataMember] public string m_strUserName =" ";[
DataMember] public string m_strPassword = " ";[
DataMember] private Hashtable m_dtAutoTable = new Hashtable(); // contain the server name and the relative Athoaction table[
DataMember] private Hashtable m_VisibleChannels = new Hashtable(); // all the visible channels per servers[
DataMember] private Hashtable m_UserAthoLevel = new Hashtable(); // all the Athorization level per severs[
DataMember] private Hashtable m_ServersNameDataMap = new Hashtable();//the all server Data listed in the XML server file while key is the server name[
DataMember] private DBManager.CDBManager m_DBmgr;[
DataMember] private string m_strConnectionString;[
DataMember] private MediaServer m_MediaServerData = new MediaServer(); //login with the curren user name and password public bool LogIn(string strUserName, string strPassword){
LogOff();
ReadServerXmlFile();
bool bRes = false; //// connect to Rss and make Authotable to each server //Read xml server //init connection //Read directly from DB the visible channel of the userm_DBmgr =
new CDBManager(); // Setup the sql strings for the logins // " + "'"+ strUserName +"'" string strAuthoLevelCmd = "SELECT AuthorizationLevel FROM Users WHERE UserName =" + "'" + strUserName + "'"; string ActionPermissiomlSqlCommand = "SELECT ActionName, Requiredlevel, AuthorizationLevel FROM UserPermissions,users where username = " + "'" + strUserName + "'" + " and pwd= " + "'" + strPassword + "'"; string CunnelSqlCommand = "SELECT * FROM Users_Channels WHERE (UserID IN (SELECT UserId FROM users WHERE UserName = " + "'" + strUserName + "'" + ")) AND (AuthorizationLevel = '1')"; int iNumOfConnection = m_ServersNameDataMap.Count; foreach (string strServerName in m_ServersNameDataMap.Keys){
ArrayList ArrUserChannels = new ArrayList(); //contain all visible channels of the user Hashtable dtAutoaction = new Hashtable(); // contain the permission per action. MediaServer msd = (MediaServer)m_ServersNameDataMap[strServerName]; int Res = -1;m_DBmgr.CreateConnection(msd.strServerName, msd.strDBName, TIMEOUT, msd.strMediaHostName,
ref Res); // get Authorization Level of user int iRes = -1; short AutoLevel = (short)m_DBmgr.ExcuteScalar(strAuthoLevelCmd, msd.strServerName, msd.strDBName, ref iRes);m_UserAthoLevel.Add(msd.strServerName, AutoLevel);
//get the user visible channel DataTable dtUserChannels = m_DBmgr.GetDataTable(CunnelSqlCommand, msd.strServerName, msd.strDBName, ref iRes); DataTable dtUserPermission = m_DBmgr.GetDataTable(ActionPermissiomlSqlCommand, msd.strServerName, msd.strDBName, ref Res); foreach (DataRow myRow in dtUserChannels.Rows){
ArrUserChannels.Add((
short)myRow["channelid"]);}
foreach (DataRow myRow in dtUserPermission.Rows){
if ((int)myRow["Requiredlevel"] > (short)m_UserAthoLevel[msd.strServerName])dtAutoaction.Add(myRow[
"ActionName"], 1);}
m_dtAutoTable.Add(msd.strServerName, dtAutoaction);
m_VisibleChannels.Add(msd.strServerName, ArrUserChannels);
iNumOfConnection--;
}
m_strUserName = strUserName;
m_strPassword = strPassword;
return bRes;}
public bool LogOff(){
bool bRes = false;m_dtAutoTable.Clear();
m_VisibleChannels.Clear();
m_ServersNameDataMap.Clear();
return bRes;}
//Read from XML File the Server Attributes public void ReadServerXmlFile(){
string strXmlFileName = null; ArrayList arrAttributesServer = null;GetXmlFileName(
ref strXmlFileName); XmlTextReader reader = new XmlTextReader(strXmlFileName); int iIndex = 0; int iIterator = 1; while (reader.Read()){
switch (reader.NodeType){
case XmlNodeType.Text: //Display the text in each element. //fill the attributes arry if (iIterator == 1){
arrAttributesServer =
new ArrayList();}
arrAttributesServer.Add(reader.Value);
iIterator++;
break;}
if ((iIterator % 7) == 0){
// m_ServersMapTable.Add(iIndex, arrAttributesServer);FillServersNameDataMap(arrAttributesServer);
iIndex++;
iIterator =
1;}
}
}
public void GetXmlFileName(ref string strXmlFileName){
const string keyName = "HKEY_LOCAL_MACHINE\\" + REG_APP_KEY_NAME + "\\";; string strKeyValue = (string)Registry.GetValue(keyName, "AppPath", "-1");strXmlFileName = strKeyValue + SERVER_LIST_FILE_NAME;
}
public void FillServersNameDataMap(ArrayList arrAttributesServer){
MediaServer msd = new MediaServer();msd.strServerName = (
string)arrAttributesServer[(int)eServerMap.eSERVER_NAME];msd.strDBName = (
string)arrAttributesServer[(int)eServerMap.eMEDIA_DB_NAME];msd.strMediaHostName = (
string)arrAttributesServer[(int)eServerMap.eMEDIAHOSTNAME];msd.strMediaPath = (
string)arrAttributesServer[(int)eServerMap.eMEDIA_PATH];msd.strAuditDBName = (
string)arrAttributesServer[(int)eServerMap.eAUDIT_DB_NAME];m_ServersNameDataMap.Add((
string)msd.strServerName, msd);}
public void GetServersNameDataMap(ref Hashtable ServerDataMap){
ServerDataMap = m_ServersNameDataMap;
}
public void GetVisibleChannels(ref Hashtable VisibleChannels){
VisibleChannels = m_VisibleChannels;
}
public void GetUserAthoLevel(ref Hashtable UserAthoLevel){
UserAthoLevel = m_UserAthoLevel;
}
// Host the service within this EXE console application. public static void Main(){
// Get base address from app settings in configuration Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]); // Create a ServiceHost for the CalculatorService type and provide the base address. using (ServiceHost serviceHost = new ServiceHost(typeof(VigUserServerData), baseAddress)){
serviceHost.Open();
// The service can now be accessed. Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service.serviceHost.Close();
}
}
}
//end the class}
my app.config file is:
<
xml version="1.0" encoding="utf-8" ><
configuration><
appSettings><!--
use appSetting to configure base address provided by host --><
add key="baseAddress" value="http://localhost:8000/servicemodelsamples/service" /></
appSettings><
system.serviceModel><
services><
service name="Microsoft.ServiceModel.Samples.VigUserServerData" behaviorConfiguration="VigUserServerDataServiceBehavior"><!--
use base address provided by host --><
endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.ServiceModel.Samples.IVigUserEx" /></
service></
services><
bindings><
wsHttpBinding><
binding name="Binding1" /></
wsHttpBinding></
bindings><!--
For debugging purposes set the returnUnknownExceptionsAsFaults attribute to true--><
behaviors><
behavior name="VigUserServerDataServiceBehavior" returnUnknownExceptionsAsFaults="False" ></
behavior></
behaviors></
system.serviceModel></
configuration>
the problem is that i got an exeptions :
System.InvalidOperationException was unhandled
Message="Service 'VigUserServerData' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because there was a problem with the type in the configuration file, or no endpoints were defined in the configuration file."
Source="System.ServiceModel"
StackTrace:
at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription description)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnBeginOpen()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at ServiceSide.VigUserServerData.Main() in D:\Vigilant\Dev\Vigilant Viewstation\VigUserHost\VigUserHost\Service.cs:line 244
i see that endpoints is empty why is that

servicehost.open
mark92929
//your config file is not correct
service name should be NAMESPACE.CLASSNAME (ServiceSide.VigUserServerData)
interface name should be NAMESPACE.INTERFACECLASS(ServiceSide.IVigUserServerEx)
I modified your config file
<
xml version="1.0" encoding="utf-8" ><
configuration><
appSettings><!--
use appSetting to configure base address provided by host --><
add key="baseAddress" value="http://localhost:8000/servicemodelsamples/service" /></
appSettings><
system.serviceModel><
services><
service name="ServiceSide.VigUserServerData" behaviorConfiguration="VigUserServerDataServiceBehavior"><!--
use base address provided by host --><
endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="ServiceSide.IVigUserServerEx" /></
service></
services><
bindings><
wsHttpBinding><
binding name="Binding1" /></
wsHttpBinding></
bindings><!--
For debugging purposes set the returnUnknownExceptionsAsFaults attribute to true--><
behaviors><
behavior name="VigUserServerDataServiceBehavior" returnUnknownExceptionsAsFaults="False" ></
behavior></
behaviors></
system.serviceModel></
configuration>Anand Kalyanam
thanks now it is Ok
but i have other problem i tried to create proxy for the client via svc util and i got some errors
i did the folowing :
Start a command prompt session.
2.Navigate to the directory where you want to place the proxy code.