Publish WCF service on IIS with test environment

Asked

Viewed 652 times

1

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

Below is the configuration 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)

Calling the Send Data method causes an error:

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.
  • Jota, in the browser, the address http://192.168. 0.101/ws_test/Servicecomunicacao.svc responds normally?

  • Do you want two Urls to access the same WCF service? Have you tried using the same endpoint name? Instead of an endpoint with Endpoint_iservicecomunicacao_teste and another with the name Endpoint_iservicecomunicacao, test with the same name.

  • Vitor, the two addresses are responding correctly by the browser.

  • Hi Renan, in case if I put the same name, how could I direct which I want via code?. To be honest, this is the first time I’ve ever dealt with WCF, I don’t really understand the function of these Endpoints. If someone has another idea of how to implement a test environment, I’m open to suggestions, can even be on separate servers type the test be on the local network and the production on the web.

1 answer

0


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

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

Follows 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    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.