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?
– Vítor Neil Avelino
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.
– Renan
Vitor, the two addresses are responding correctly by the browser.
– JotaSantana
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.
– JotaSantana