WCF InvalidOperationException:绑定实例已关联到侦听 URI [英] WCF InvalidOperationException: A binding instance has already been associated to listen URI
问题描述
我是 WCF 的初学者,正在学习 Essential WCF.
I'm a beginner of WCF and I'm studying in Essential WCF.
我在使用 ServiceContract NameSpace 和 Name 时遇到问题.当我运行代码时,我捕获了一个波纹管 InvalidOperationException.但是我看不清楚.
I encountered a problem when using ServiceContract NameSpace and Name. when I run the code, I catch a bellow InvalidOperationException. But I couldn't understand clearly.
绑定实例已经关联到侦听 URI 'http://localhost:8080/NamespaceChange01'.如果两个端点想要共享同一个 ListenUri,它们也必须共享同一个绑定对象实例.两个冲突的端点要么在 AddServiceEndpoint() 调用中指定,要么在配置文件中指定,要么在 AddServiceEndpoint() 和配置的组合中指定.
有人知道如何避免 InvalidOperationException 吗?
Does anyone knows how to avide the InvalidOperationException ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace NamespaceChange01
{
[ServiceContract(Name = "MyServiceName", Namespace = "http://ServiceNamespace")]
public interface IBurgerMaster
{
[return: MessageParameter(Name = "myOutput")]
[OperationContract(Name = "OperationName", Action = "OperationAction", ReplyAction = "ReplyActionName")]
double GetStockPrice(string ticker);
}
[ServiceBehavior(Namespace = "http://MyService")]
public class BurgerMaster : IBurgerMaster
{
public double GetStockPrice(string ticker)
{
return 100.99;
}
}
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(BurgerMaster));
host.Open();
Console.ReadLine();
host.Close();
}
}
}
app.config
app.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="NamespaceChange01.BurgerMaster" behaviorConfiguration="mexServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8080/NamespaceChange01"/> </baseAddresses> </host> <endpoint name="basic" binding="basicHttpBinding" contract="NamespaceChange01.IBurgerMaster"/> <endpoint name="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="mexServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
谢谢.
推荐答案
两个端点(basic 和 mex)不能在同一个地址上.为其中一个(或两个)添加一些特定地址.
Two endpoints (basic and mex) couldn't be on the same address. Add some specific address for one of them (or for both ones).
例如:
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
这篇关于WCF InvalidOperationException:绑定实例已关联到侦听 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!