0

How can I add a Service Reference (WCF) without use the Solution Explorer and "Add Service Reference".

Hi everyone, I've added a Service Reference using the Solution Explorer and it works perfectly but now I need to add the Service Reference by code in C# I don't want to use the App.config file, all to do by code. I looked for in many sites but all use the Solution Explorer.

Please, give me some help with this.

This is my code.

BasicHttpBinding _enlace = new BasicHttpBinding();
_enlace.Security.Mode = BasicHttpSecurityMode.None;
EndpointAddress _direccion = new EndpointAddress("http://192.168.1.42/ServicioManejoArchivos.svc/ServicioManejoArchivos");
ServicioManejoArchivosClient _servicio = new ServicioManejoArchivosClient(_enlace, _direccion);
Documento _archivoEnviar = new Documento();
byte[] _cadenaBytes = File.ReadAllBytes(m_direccionArchivoTemporal);
_archivoEnviar.Archivo = _cadenaBytes;
_archivoEnviar.CodigoEmpresa = m_global.CodigoEmpresa;
_archivoEnviar.CodigoFacilidad = m_global.CodigoFacilidad;
_archivoEnviar.CodigoTercero = m_codigoTercero;
_archivoEnviar.Extension = ".zip";
_archivoEnviar.NombreArchivo = System.IO.Path.GetFileNameWithoutExtension(m_direccionArchivoTemporal);
_archivoEnviar.TipoDocumento = cmbTipoDocumento.Text;
_archivoEnviar.ModuloAfectado = m_global.CodigoArea;
_archivoEnviar.ProcesoEfectuado = base.m_tipoActividad.ToString();
var resultado = _servicio.GuardarArchivo(_archivoEnviar);
_servicio.Close();
Jim
  • 2,974
  • 2
  • 19
  • 29
MagnunStalin
  • 94
  • 1
  • 9
  • how do you expect to get strong typing on your service if you're in effect adding a service at run time? Why are you trying to do it this way? – Kritner Nov 23 '16 at 23:20
  • 1
    As @Kritner pointed, there's no way your code can, total dynamically, discover a service contract and consume the operations without know it (how can provide values to an operation that you don't even know the name and required parameters?). Anyway, you can dynamically create a proxy, read more here: http://stackoverflow.com/questions/27145485/consume-and-invoke-soap-webservices-at-runtime-dynamic-web-service-client-from – Ricardo Pontual Nov 24 '16 at 10:21
  • @RicardoPontual thanks that is I want. – MagnunStalin Nov 24 '16 at 14:12

0 Answers0