我是WCF的初學者,我正在學習Essential WCF。WCF InvalidOperationException:綁定實例已經關聯到偵聽URI
使用ServiceContract NameSpace和Name時遇到問題。當我運行代碼時,我捕捉到一個InvalidOperationException異常。但我不明白。
一個綁定實例已經關聯到偵聽URI'http:// localhost:8080/NamespaceChange01'。如果兩個端點想要共享相同的ListenUri,則它們也必須共享相同的綁定對象實例。兩個衝突的端點是在AddServiceEndpoint()調用,配置文件或AddServiceEndpoint()和config的組合中指定的。
有誰知道如何面對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
<?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>
感謝。
這是不正確-1 - 在OP的代碼是完全有效的。這是不正確的配置 – 2012-07-16 15:17:04