Error listing client in WCF

0

I am trying to list a client with WCF and this error appears to me and I have seen that before many people have done it this way, maybe it is configuaración.

Error message:

[! [enter the description of the image here] [1]] [1]

And this is the code:

public List<Datos.cliente> listarClientesGeneral()
{
    using (TallerRefuerzoEntities conexto = new TallerRefuerzoEntities())
    {
        return conexto.cliente.ToList();
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfHotel
{    
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        List<Datos.cliente> listarClientesGeneral();
    }
}

In the web.config I have this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>
  <connectionStrings>
     <add name="TallerRefuerzoEntities" connectionString="metadata=res://*/Datos.Model1.csdl|res://*/Datos.Model1.ssdl|res://*/Datos.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DORADO-PC;initial catalog=TallerRefuerzo;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

This is my error when invoking in the wcf test client and in the bottom part I will place the error when uploading it to the iis, it may be useful:

The service could not be invoked. Possible causes: the service is offline or inaccessible. the client configuration does not match the proxy; The existing proxy is not valid. See the stack trace for more information. To try recovery, start a new proxy, restore the default settings or update the service.

Error receiving HTTP response to link . It may be because the service end link does not use the HTTP protocol. It may also be due to the server overriding an HTTP request context (possibly due to the closure of the service). Check server logs for more information.

Server stack trace:    in System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException (WebException WebException, HttpWebRequest request, HttpAbortReason abortReason)    in System.ServiceModel.Channels.HttpChannelFactory'1.HttpRequestChannel.HttpChannelRequest.WaitForReply (TimeSpan timeout)    in System.ServiceModel.Channels.RequestChannel.Request (Message message, TimeSpan timeout)    in System.ServiceModel.Dispatcher.RequestChannelBinder.Request (Message message, TimeSpan timeout)    in System.ServiceModel.Channels.ServiceChannel.Call (String action, Boolean oneway, ProxyOperationRuntime operation, Object [] ins, Object [] outs, TimeSpan timeout)    in System.ServiceModel.Channels.ServiceChannelProxy.InvokeService (IMethodCallMessage methodCall, ProxyOperationRuntime operation)    in System.ServiceModel.Channels.ServiceChannelProxy.Invoke (IMessage message)

Exception rethrown at [0]:    in System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage (IMessage reqMsg, IMessage retMsg)    in System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke (MessageData & msgData, Int32 type)    in IService1.List ()    in Service1Client.List ()

Inner Exception: The connection is terminated: Unexpected reception error.    in System.Net.HttpWebRequest.GetResponse ()    in System.ServiceModel.Channels.HttpChannelFactory'1.HttpRequestChannel.HttpChannelRequest.WaitForReply (TimeSpan timeout)

Inner Exception: Unable to write data to the transport connection: The interruption of an existing connection by the remote host has been forced.    in System.Net.Sockets.NetworkStream.Read (Byte [] buffer, Int32 offset, Int32 size)    in System.Net.PooledStream.Read (Byte [] buffer, Int32 offset, Int32 size)    in System.Net.Connection.SyncRead (HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

Inner Exception: The interruption of an existing connection has been forced by the remote host    in System.Net.Sockets.Socket.Receive (Byte [] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)    in System.Net.Sockets.NetworkStream.Read (Byte [] buffer, Int32 offset, Int32 size)

    
asked by Alexis Dorado Muñoz 21.04.2017 в 19:03
source

2 answers

2

The error is due to binding , you want to start with http but you have set https :

<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

Change the protocolMapping or add it so that you also have http in the following way:

<protocolMapping>
    <add binding="basicHttpBinding" scheme="http" />
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>

If you notice, your localhost wants to access via http, which is currently not configured.

    
answered by 22.04.2017 в 00:27
0

Based on your webConfig, it is very likely seeing this line:

<add name="TallerRefuerzoEntities" connectionString="metadata=res://*/Datos.Model1.csdl|res://*/Datos.Model1.ssdl|res://*/Datos.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DORADO-PC;initial catalog=TallerRefuerzo;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

that the user with whom the program is running does not have access to the DB

data source=DORADO-PC;initial catalog=TallerRefuerzo;integratedsecurity=True;

There are 2 things you can do (they are optional and exclusive, so you should only try one option, both at the same time they have no case):

A). Use Impersonate (just add this to the webconfig):

NOTE: Be sure to enter a username and password if you have access to the DB

    <system.web>
      <authentication mode="Windows"/>
      <identity impersonate="true" userName="usuario" password="contraseña"/>
    </system.web>

B). Create a BD user for the system, thus connect using user and password (You would have to update the web.Config connection string):

    data source=(local);initial catalog=BisVales;user id=sa;password=123456789;
    
answered by 21.04.2017 в 23:41