J'ai un simple programme de discussion utilisant le service WCF. Une utilisation de service pour le serveur et une autre utilisation pour le client. Ces services se connectent les uns aux autres et s'appellent les uns les autres. Pour le serveur d'hébergement, j'ai utilisé un service Windows et pour le client j'héberge le service WCF dans une application Windows. Après tout, j'ai trouvé que ce code fonctionne sur un ordinateur simple, mais quand déplacer le service du serveur à un autre ordinateur une exception soulevée et le serveur ne peut pas se connecter au client. J'ai cherché et essayé d'autres façons. Je reçois un résultat: * SI L'HÔTE DE SERVICE WCF DANS L'APPLICATION WINDOWS U NE PEUT PAS SE CONNECTER À CELUI-CI, FORMER UN AUTRE ORDINATEUR. * CE CODE A TRAVAILLÉ UNIQUEMENT LORSQUE J'AI UTILISÉ DEUX SERVICES WINDOWS (hébergement du service client WCF dans un service Windows) Mais je veux savoir COMMENT héberger le service WCF dans l'application Windows qui peut se connecter et travailler avec d'autres services? Ceci est mon code Code client: Manager.csProblème de services WCF? (Connexion bidirectionnelle)
public delegate void UserInfoHandeler(string UserName);
public delegate void MessageHandeler(string Message);
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Manager : IClientPoint
{
public void SendUserList(string[] users)
{
frmRoom.Members = users; // this method called by Server (WCF service which host in windows service)
//when server call this method I have an exception with SSPI
}
public void SendMessage(string message)
{
frmRoom.ReciveMessage = message; // this method called by Server (WCF service which host in windows service)
//when server call this method I have an exception with SSPI
}
FrmJoin frmJoin;
FrmRoom frmRoom;
ChatServerClient ServiceInvoker;
public string User
{
get;
set;
}
public void Run()
{
frmJoin = new FrmJoin();
frmJoin.LoginEvent += new UserInfoHandeler(frmJoin_LoginEvent);
ServiceInvoker = new ChatServerClient("WSHttpBinding_ChatServer", Settings.Default.ChatServerAddress);
frmJoin.ShowDialog();
}
void frmJoin_LoginEvent(string UserName)
{
frmRoom = new FrmRoom();
frmRoom.SendMessageEvent += new MessageHandeler(frmRoom_SendMessageEvent);
frmJoin.LogoutEvent += new UserInfoHandeler(frmJoin_LogoutEvent);
User = UserName;
frmRoom.ReciveMessage = ServiceInvoker.Login(User, Settings.Default.ClientPointAddress);
frmRoom.ShowDialog();
}
void frmJoin_LogoutEvent(string UserName)
{
string message = ServiceInvoker.Logout(UserName, Settings.Default.ChatServerAddress);
}
void frmRoom_SendMessageEvent(string Message)
{
ServiceInvoker.SendMessage(User, Message);
} }
config client:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_Config" closeTimeout="00:05:00"
openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
<binding name="MyConfig" closeTimeout="00:10:00" openTimeout="00:10:00"
sendTimeout="00:10:00" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Config"
contract="Host.IChatServer" name="WSHttpBinding_ChatServer">
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="Room.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Room.Service1Behavior" name="Room.Manager">
<endpoint address="" binding="wsHttpBinding" contract="Room.IClientPoint" bindingConfiguration="WSHttpBinding_Config">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
http://PChost:8731/ClientPoint/ http://PCserver:8731/ChatServer/
Code Serveur: [ServiceBehavior (InstanceContextMode = InstanceContextMode.Single)] public class ChatServer: IChatServer { clients Dictionnaire;
public ChatServer()
{
clients = new Dictionary<string, ClientInvoker>();
}
public string Login(string Username, string address)
{
try
{
ClientInvoker client = new ClientInvoker("WSHttpBinding_ClientPoint", address);
clients.Add(Username, client);
foreach (ClientInvoker clientinvoker in clients.Values)
clientinvoker.SendUserList(clients.Keys.ToArray());
}
catch (Exception e)
{
File.AppendAllText(@"c:\ServiceChatLog.txt", "Service trow Exeption \n");
File.AppendAllText(@"c:\ServiceChatLog.txt", e.ToString() + " \n");
}
return string.Format("Welcom {0}", Username);
}
public string[] GetListUser()
{
return clients.Keys.ToArray();
}
public void SendMessage(string userName, string ReciveMessage)
{
string message = string.Format("{0} : {1}", userName, ReciveMessage);
foreach (ClientInvoker clientinvoker in clients.Values)
clientinvoker.SendMessage(message);
}
public string Logout(string Username, string address)
{
clients.Remove(Username);
foreach (ClientInvoker clientinvoker in clients.Values)
{
clientinvoker.SendUserList(clients.Keys.ToArray());
clientinvoker.SendMessage(string.Format("{0} left ROOM", Username));
}
return string.Format("Godbye {0}", Username);
}
}
config serveur:
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Config"
contract="Room.IClientPoint" name="WSHttpBinding_ClientPoint">
</endpoint>
</client>
merci pour U'r aide – Rev
bon article est ici http://www.codeproject.com/KB/WCF/WCFDuplexReentrant.aspx – Rev