Publish WCF service in IIS with test environment

1

I created a webservice using WCF .NET 4.0, and hosted it on IIS from our local server (when everything is ok it will be migrated to a web server). In the winform application I was able to consume the method without problems, however I'm trying to create a test environment with a different url, and I could not configure web.config / app.config correctly for this. I tried using baseAddress and two different EndPoints.

The following configuration is used: (web.config - WCF ServiceHost)

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IServiceComunicacao" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxStringContentLength="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="mexBehavior" name="WsComunicacao.ServiceComunicacao">
    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.0.101/" />
      </baseAddresses>
    </host>
    <endpoint address="ws_teste/ServiceComunicacao.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceComunicacao"
        contract="WsComunicacao.IServiceComunicacao" name="EndPoint_IServiceComunicacao_Teste" />

    <endpoint address="ws/ServiceComunicacao.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceComunicacao"
        contract="WsComunicacao.IServiceComunicacao" name="EndPoint_IServiceComunicacao" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="mexBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false"/>
</system.webServer>

(app.config - WinForm Client App)

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IServiceComunicacao" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647"/>
        </binding>        
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.0.101/ws_teste/ServiceComunicacao.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceComunicacao"
          contract="WsComunicacao.IServiceComunicacao" name="EndPoint_IServiceComunicacao_Teste" />

      <endpoint address="http://192.168.0.101/ws/ServiceComunicacao.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceComunicacao"
          contract="WsComunicacao.IServiceComunicacao" name="EndPoint_IServiceComunicacao" />
    </client>
</system.serviceModel>

And the code used to consume the webservice:

Dim wsClient As WsComunicacao.ServiceComunicacaoClient
If Debugger.IsAttached Then
    wsClient = New WsComunicacao.ServiceComunicacaoClient("EndPoint_IServiceComunicacao_Teste")
Else
    wsClient = New WsComunicacao.ServiceComunicacaoClient("EndPoint_IServiceComunicacao")
End If

Dim resp As WsComunicacao.Resposta = wsClient.EnviarDados(dados)

When calling the SendData method, the error occurs:

There was no endpoint listening at http://192.168.0.101/ws_teste/ServiceComunicacao.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
    
asked by anonymous 11.12.2014 / 20:31

1 answer

0

I'll answer the question if anyone is in the same situation. After searching a lot I decided to make the configuration via code instead of using .ini, the framework provides properties to configure all parameters available in .ini, making it much easier to customize.

This also solved another major problem, in my case my routine was in a Dll that was backed up in other executables, so I would have to configure the app.config on each of these executables.

Follow the code used:

Private Function ObterConexaoWebservice() As WsComunicacao.IServiceComunicacaoChannel
    Try
        If _wsComunicacao Is Nothing Then
            Dim b As New WSHttpBinding
            b.MaxBufferPoolSize = 2147483647
            b.MaxReceivedMessageSize = 2147483647
            b.ReaderQuotas.MaxStringContentLength = 2147483647
            b.Security.Mode = SecurityMode.None
            b.SendTimeout = New TimeSpan(0, 10, 0)

            'Dim edp As New EndpointAddress("http://192.168.0.101/ws_teste/ServiceComunicacao.svc")
            'Dim edp As New EndpointAddress("http://localhost:2392/WcfServiceHost/ServiceComunicacao.svc")
            Dim edp As New EndpointAddress(DadosConfigGerais.ConfigSistema.url_wscomunicacao)
            Dim fab As New ChannelFactory(Of WsComunicacao.IServiceComunicacaoChannel)(b, edp)
            _wsComunicacao = fab.CreateChannel
            _wsComunicacao.Open()
        End If

        Return _wsComunicacao
    Catch ex As Exception
        Throw
    End Try
End Function    
    
15.07.2015 / 21:05