Ich würde meinen WCF-Dienst auf mehreren Endpunkten verfügbar machen. Ich verstehe nicht, warum dieser Fehler, da jeder Endpunkt eindeutige Adresse hat.WCF mehrere Endpunkte
Muss ich den mex-Endpunkt für jeden einzelnen Endpunkt offenlegen?
Fehler ist:
System.InvalidOperationException: Eine verbindliche Instanz bereits zugeordnet wurde URI 'http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/' hört. Wenn zwei Endpunkte dieselbe ListenUri teilen möchten, müssen sie dieselbe Binding-Objektinstanz ebenfalls teilen. Die beiden widersprüchlichen Endpunkte wurden entweder in AddServiceEndpoint() - Aufrufen, in einer Konfigurationsdatei oder in einer Kombination aus AddServiceEndpoint() und config angegeben. bei System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost (Servicedescription Beschreibung, Servicehostservicehost) bei System.ServiceModel.ServiceHostBase.InitializeRuntime() bei System.ServiceModel.ServiceHostBase.OnOpen (Timespan timeout) bei System.ServiceModel.Channels. CommunicationObject.Open (Timespan timeout) bei Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService (Serviceinfo info)
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;
}
}
}
Konfigurationsdatei:
<?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>
Zwei Endpunkte (unverwässert und mex) nicht auf derselben Adresse sein könnte. Fügen Sie eine spezifische Adresse für eine von ihnen hinzu (oder für beide). Hilft es dir? –
Ich habe 'mex' am Ende jedes mexHttpBinding hinzugefügt, aber der Fehler ist immer noch da. – FrenkyB
Müssen Sie mehrere Metadaten-Endpunkte setzen oder dies ist engough –