He pasado un par de horas buscando sobre este error, y he probado casi todo lo que está en Google.Metadatos WCF contiene una referencia que no se puede resolver
Quiero acceder a un servicio usando TCP, .NET4 y VS2010, en C#.
Tengo una muy pequeña del servicio:
namespace WcfService_using_callbacks_via_tcp
{
[ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
public interface IService1
{
[OperationContract]
string Test(int value);
}
public interface ICallback
{
[OperationContract(IsOneWay = true)]
void ServerToClient(string sms);
}
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class Service1 : IService1
{
public string Test(int value)
{
ICallback the_callback = OperationContext.Current.GetCallbackChannel<ICallback>();
the_callback.ServerToClient("Callback from server, waiting 1s to return value.");
Thread.Sleep(1000);
return string.Format("You entered: {0}", value);
}
}
}
Con esta Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfService_using_callbacks_via_tcp.Service1" behaviorConfiguration="Behaviour_Service1">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5050/Service1" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" bindingConfiguration="DuplexNetTcpBinding_IService1" contract="WcfService_using_callbacks_via_tcp.IService1"/>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="mexTcp" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<!--
TCP Binding
-->
<netTcpBinding>
<binding name="DuplexNetTcpBinding_IService1" sendTimeout="00:00:01"
portSharingEnabled="true">
</binding>
<binding name="mexTcp" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<!--
Behaviour to avoid a rush of clients and to expose metadata over tcp
-->
<behavior name="Behaviour_Service1">
<serviceThrottling maxConcurrentSessions="10000"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Y Thi código s de ser el anfitrión:
static void Main(string[] args)
{
Uri base_address = new Uri("net.tcp://localhost:5050/Service1");
ServiceHost host = null;
try
{
// Create the server
host = new ServiceHost(typeof(Service1), base_address);
// Start the server
host.Open();
// Notify it
Console.WriteLine("The service is ready at {0}", base_address);
// Allow close the server
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close it
host.Close();
}
catch (Exception ex)
{
// Opus an error occurred
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("Host error:\r\n{0}:\r\n{1}", ex.GetType(), ex.Message));
Console.ReadLine();
}finally
{
// Correct memory clean
if(host != null)
((IDisposable)host).Dispose();
}
}
Ahora quiero crear el cliente, pero no es posible. He usado Agregar referencia de servicio y Svcutil directamente, pero estoy recibiendo este error:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>svcutil.exe net.tcp://loc alhost:5050/Service1 Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1] Copyright (c) Microsoft Corporation. All rights reserved.
Attempting to download metadata from 'net.tcp://localhost:5050/Service1' using W S-Metadata Exchange. This URL does not support DISCO. Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1] Copyright (c) Microsoft Corporation. All rights reserved.
Error: Cannot obtain Metadata from net.tcp://localhost:5050/Service1
If this is a Windows (R) Communication Foundation service to which you have acce ss, please check that you have enabled metadata publishing at the specified addr ess. For help enabling metadata publishing, please refer to the MSDN documentat ion at http://go.microsoft.com/fwlink/?LinkId=65455 .
WS-Metadata Exchange Error URI: net.tcp://localhost:5050/Service1
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost: 5050/Service1'.
The socket connection was aborted. This could be caused by an error processi ng your message or a receive timeout being exceeded by the remote host, or an un derlying network resource issue. Local socket timeout was '00:04:59.9863281'.
Se ha forzado la interrupción de una conexión existente por el host remoto
If you would like more help, type "svcutil /?"
lo tanto, puedo alojar el servicio sin problemas, pero no puedo crear los proxies.
He intentado con casi cualquier configuración que he encontrado, pero creo que la web.config actual es correcta. Existen los comportamientos, la seguridad y los enlaces que usan mex, utilizados por los puntos finales.
He intentado crear un app.config y configurarlo en la misma carpeta con svcutil.exe.
@JohnSaunders, no puedo comprender por qué alguien con su reputación copiaría el código de respuesta en el código de la pregunta, lo que invalidaría por completo toda esta pregunta. Solo perdí el tiempo tratando de resolver la diferencia entre el código de pregunta y el código de respuesta antes de darme cuenta de que alguien había hecho lo que tú hiciste ... ¿Cuál es el beneficio al hacer eso? Nadie podía saber cuál era la verdadera pregunta. – Sheridan
@Sheridan: aquí hay una gran sugerencia de vida: cada vez que te encuentras diciendo cosas como "No puedo entender cómo" o "No puedo ver cómo", considera que podría ser una cuestión de tu comprensión o tu visión . Usted "no puede entender cómo" porque no lo hice. Acabo de sangrar el código. Eche un vistazo más de cerca al historial de edición. Lo acabo de hacer. –
I * did * eché un vistazo de cerca * antes * de mi comentario y, aunque acepto su comentario, me gustaría decir que aún * aparece * como si hubiera agregado ese código ... ahhh ... eso está solo en el * Vista de lado a lado *. En las otras vistas, puedo ver la verdadera imagen. Disculpas ... Debería haber mirado más de cerca antes de comentar. – Sheridan