我想在多個端點上公開我的WCF服務。 我不明白爲什麼會出現這個錯誤,因爲每個端點都有唯一的地址。WCF多個端點
我必須爲每個單獨的端點公開mex端點嗎?
錯誤是:
System.InvalidOperationException:有約束力的實例已經關聯到聽URI 'http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/'。如果兩個端點想要共享相同的ListenUri,則它們也必須共享相同的綁定對象實例。兩個衝突的端點是在AddServiceEndpoint()調用,配置文件或AddServiceEndpoint()和config的組合中指定的。 在System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription描述,ServiceHostBase的ServiceHost) 在System.ServiceModel.ServiceHostBase.InitializeRuntime() 在System.ServiceModel.ServiceHostBase.OnOpen(時間跨度超時) 在System.ServiceModel.Channels。 CommunicationObject.Open(時間跨度超時) 在Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo資訊)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
// You can add XSD files into the project. After building the project, you can directly use the data types defined there, with the namespace "WcfServiceLibrary1.ContractType".
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1" name="first" />
<endpoint address="http://localhost:8734/Design_Time_Addresses/WcfServiceLibrary1/Service2/"
binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1" name="second" />
<endpoint address="http://localhost:8735/Design_Time_Addresses/WcfServiceLibrary1/Service3/"
binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1" name="third" />
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost:8734/Design_Time_Addresses/WcfServiceLibrary1/Service2/" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost:8735/Design_Time_Addresses/WcfServiceLibrary1/Service3/" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
兩個端點(基本和MEX)不能在同一個地址。爲其中一個(或兩個)添加一些特定的地址。它對你有幫助嗎? –
我在每個mexHttpBinding的末尾添加了'mex',但錯誤仍然存在。 – FrenkyB
您是否必須放置多個元數據終結點或這是簡單的<端點地址=「mex」綁定=「mexHttpBinding」合同=「IMetadataExchange」/> –