私はWCFを初めて使用します。Windows形式でwcfサービスをホストする方法を知っています。今私は.svcファイルを持っている小さなwcfサービスを開発します。このsvcファイルをwin形式でホストしたいと思います。プロセスが同じか異なるかを知りたいだけですか?
これが私のsvcファイルのマークアップです
<%@ ServiceHost Language="C#" Debug="true"
Service="Services.ChatService" CodeBehind="ChatService.svc.cs" %>
これは、ファイルの背後にあるsvcファイルコード内の小さなコードです
namespace Services
{
/// <summary>
/// Implements the chat service interface.
/// </summary>
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
public class ChatService : IChatService
{
private readonly Dictionary<Guid, IChatServiceCallback> clients =
new Dictionary<Guid, IChatServiceCallback>();
#region IChatService
Guid IChatService.Subscribe()
{
IChatServiceCallback callback =
OperationContext.Current.GetCallbackChannel<IChatServiceCallback>();
Guid clientId = Guid.NewGuid();
if (callback != null)
{
lock (clients)
{
clients.Add(clientId, callback);
}
}
return clientId;
}
void IChatService.Unsubscribe(Guid clientId)
{
lock (clients)
{
if (clients.ContainsKey(clientId))
{
clients.Remove(clientId);
}
}
}
void IChatService.KeepConnection()
{
// Do nothing.
}
void IChatService.SendMessage(Guid clientId, string message)
{
BroadcastMessage(clientId, message);
}
#endregion
/// <summary>
/// Notifies the clients of messages.
/// </summary>
/// <param name="clientId">Identifies the client that sent the message.</param>
/// <param name="message">The message to be sent to all connected clients.</param>
private void BroadcastMessage(Guid clientId, string message)
{
// Call each client's callback method
ThreadPool.QueueUserWorkItem
(
delegate
{
lock (clients)
{
List<Guid> disconnectedClientGuids = new List<Guid>();
foreach (KeyValuePair<Guid, IChatServiceCallback> client in clients)
{
try
{
client.Value.HandleMessage(message);
}
catch (Exception)
{
// TODO: Better to catch specific exception types.
// If a timeout exception occurred, it means that the server
// can't connect to the client. It might be because of a network
// error, or the client was closed prematurely due to an exception or
// and was unable to unregister from the server. In any case, we
// must remove the client from the list of clients.
// Another type of exception that might occur is that the communication
// object is aborted, or is closed.
// Mark the key for deletion. We will delete the client after the
// for-loop because using foreach construct makes the clients collection
// non-modifiable while in the loop.
disconnectedClientGuids.Add(client.Key);
}
}
foreach (Guid clientGuid in disconnectedClientGuids)
{
clients.Remove(clientGuid);
}
}
}
);
}
}
}
ここに拘束力のある情報があります
<service behaviorConfiguration="Services.ChatServiceBehavior" name="Services.ChatService">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IChatService" contract="Services.IChatService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
これは、wsDualHttpBinding用とmex用の2つのエンドポイントであるため 、mexエンドポイントは
http://localhost:49722/ChatService.svc?wsdl
ここで、別のtcpエンドポイントを追加し、このサービスを2つのエンドポイントで公開したいと思います。したがって、tcpエンドポイントに何を書き込む必要があるかを教えてください。tcpエンドポイントを追加すると、tcpのエンドポイントは何になりますか。ユーザーが2つのURLのいずれかでプロキシを作成できるようにするためです。1つはhttp urlで、もう1つはtcpurlです。だから私はここにtcpのmexを追加する必要がありますか?
案内してください。ありがとう