はい、アプリをクライアントとサーバーの両方として機能させることができます。
修正が必要なことがいくつかあります。まず、OperationContractを追加してみてください。
[ServiceContract]
public interface IShout
{
[OperationContract]
String Broadcast(String message);
}
次に、インターフェイスではなく、クラスのタイプを取得します。
ServiceHost s = new ServiceHost(typeof(eveShout));
s.AddServiceEndpoint(typeof(IShout), new BasicHttpBinding(), "http://localhost:9189");
s.Open();
名前空間にアクセスする権限があることを確認してください(s.Open()が例外をスローしない場合は、例外をスローする必要があります)。
net http add urlacl url=http://+:9189/ user=...
これらの提案が役立つかどうかを確認してください。
(そうそう、クラスでBroadcastを公開する)
簡単な例のWindowsFormsApplicationは次のようになります...
// form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ChannelFactory<IShout> channel = new ChannelFactory<IShout>(new BasicHttpBinding(), "http://localhost:9189");
IShout shout = channel.CreateChannel();
String reply = shout.Broadcast("Test");
}
}
}
// and Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.ServiceModel;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ServiceHost s = new ServiceHost(typeof(eveShout));
s.AddServiceEndpoint(typeof(IShout), new BasicHttpBinding(), "http://localhost:9189");
s.Open();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class eveShout : IShout
{
public String Broadcast(String message)
{
return message + " reply";
}
}
[ServiceContract]
public interface IShout
{
[OperationContract]
String Broadcast(String message);
}
}
これが機能するのと同じくらい簡単なものを手に入れることができるかどうかを確認してください。それは少なくともあなたにそれができること、そして問題がどこかにあることを証明するでしょう。