Tôi là người mới bắt đầu của WCF và tôi đang học trong WCF thiết yếu.WCF InvalidOperationException: Một cá thể ràng buộc đã được liên kết để nghe URI
Tôi gặp sự cố khi sử dụng ServiceContract NameSpace và Name. khi tôi chạy mã, tôi bắt được một InvalidOperationException dưới đây. Nhưng tôi không thể hiểu rõ.
Một cá thể ràng buộc đã được liên kết để nghe URI 'http: // localhost: 8080/NamespaceChange01'. Nếu hai thiết bị đầu cuối muốn chia sẻ cùng một ListenUri, chúng cũng phải chia sẻ cùng một cá thể đối tượng ràng buộc. Hai điểm cuối xung đột đã được chỉ định trong các cuộc gọi AddServiceEndpoint(), trong tệp cấu hình hoặc kết hợp của AddServiceEndpoint() và cấu hình.
Có ai biết cách thực hiện ngoại lệ InvalidOperationException không?
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>
Cảm ơn.
-1 này là không chính xác - mã của OP là hoàn toàn hợp lệ. Đây là cấu hình không chính xác –