Skip to content

Instantly share code, notes, and snippets.

@goldshtn
Created January 20, 2014 14:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
An example of a WCF service that causes metadata publishing to fail such that "Add Service Reference" reports a cryptic failure.
[ServiceContract]
interface IChatClient
{
[OperationContract(IsOneWay = true)]
void Message(string message);
}
[ServiceContract(CallbackContract = typeof(IChatClient))]
interface IChatService
{
[OperationContract(IsOneWay = true)]
void Message(string message);
}
class ChatService : IChatService
{
public void Message(string message)
{
// Echo the message
var client = OperationContext.Current.GetCallbackChannel<IChatClient>();
client.Message(message);
}
}
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(ChatService));
host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = new Uri("http://localhost:9091/mex") });
host.AddServiceEndpoint(typeof(IChatService), new NetTcpBinding(SecurityMode.None), "net.tcp://localhost:9090/chat");
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "http://localhost:9091/mex");
host.Open();
Console.WriteLine("Host is listening.");
foreach (var endpoint in host.Description.Endpoints)
Console.WriteLine("\t{0} {1}", endpoint.Address, endpoint.Contract.Name);
Console.ReadLine();
host.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment