Created
January 20, 2014 14:11
-
-
Save goldshtn/8520536 to your computer and use it in GitHub Desktop.
An example of a WCF service that causes metadata publishing to fail such that "Add Service Reference" reports a cryptic failure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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