Usuário com melhor resposta
Erro ao publicar WCF Service

Pergunta
-
Olá, Boa noite !
Estou cá eu na aula de Administração tentando publicar meu serviço WCF na web!
Criei um WCF Service que funciona normalmente debugando, ja consumi ele com minha aplicação em Silverlight.
Mas quando eu publico ele no meu domínio na Locaweb, dá um erro:
Server Error in '/' Application.
This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Parameter name: item
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item]
System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item) +11520590
System.Collections.Generic.SynchronizedCollection`1.Add(T item) +67
System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses) +49
System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) +129
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) +28
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +331
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11659932
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
[ServiceActivationException: The service '/Service1.svc' cannot be activated due to an exception during compilation. The exception message is: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item.]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +11531006
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.4028
Já vou me adiantar e postar o meu Web.config ->
BODY{font:x-small 'Verdana';margin-right:1.5em} .c{cursor:hand} .b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none} .e{margin-left:1em;text-indent:-1em;margin-right:1em} .k{margin-left:1em;text-indent:-1em;margin-right:1em} .t{color:#990000} .xt{color:#990099} .ns{color:red} .dt{color:green} .m{color:blue} .tx{font-weight:bold} .db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier} .di{font:small Courier} .d{color:blue} .pi{color:blue} .cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888} .ci{font:small Courier;color:#888888} PRE{margin:0px;display:inline} <script><!-- function f(e){ if (e.className=="ci"){if (e.children(0).innerText.indexOf("\n")>0) fix(e,"cb");} if (e.className=="di"){if (e.children(0).innerText.indexOf("\n")>0) fix(e,"db");} e.id=""; } function fix(e,cl){ e.className=cl; e.style.display="block"; j=e.parentElement.children(0); j.className="c"; k=j.children(0); k.style.visibility="visible"; k.href="#"; } function ch(e){ mark=e.children(0).children(0); if (mark.innerText=="+"){ mark.innerText="-"; for (var i=1;i<e.children.length;i++) e.children(i).style.display="block"; } else if (mark.innerText=="-"){ mark.innerText="+"; for (var i=1;i<e.children.length;i++) e.children(i).style.display="none"; }} function ch2(e){ mark=e.children(0).children(0); contents=e.children(1); if (mark.innerText=="+"){ mark.innerText="-"; if (contents.className=="db"||contents.className=="cb") contents.style.display="block"; else contents.style.display="inline"; } else if (mark.innerText=="-"){ mark.innerText="+"; contents.style.display="none"; }} function cl(){ e=window.event.srcElement; if (e.className!="c"){e=e.parentElement;if (e.className!="c"){return;}} e=e.parentElement; if (e.className=="e") ch(e); if (e.className=="k") ch2(e); } function ex(){} function h(){window.status=" ";} document.onclick=cl; --></script>
<? xml version="1.0" ?>- < sectionGroup name =" system.web.extensions " type =" System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " >- < sectionGroup name =" scripting " type =" System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " >< section name =" scriptResourceHandler " type =" System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " requirePermission =" false " allowDefinition =" MachineToApplication " />- < sectionGroup name =" webServices " type =" System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " >< section name =" jsonSerialization " type =" System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " requirePermission =" false " allowDefinition =" Everywhere " />< section name =" profileService " type =" System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " requirePermission =" false " allowDefinition =" MachineToApplication " />< section name =" authenticationService " type =" System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " requirePermission =" false " allowDefinition =" MachineToApplication " />< section name =" roleService " type =" System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " requirePermission =" false " allowDefinition =" MachineToApplication " /></ sectionGroup ></ sectionGroup ></ sectionGroup ></ configSections >< appSettings />< connectionStrings />< customErrors mode =" Off " />< add assembly =" System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089 " />< add assembly =" System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089 " />< add assembly =" System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />< add assembly =" System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089 " /></ assemblies ></ compilation >- <!--The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user.
-->< authentication mode =" Windows " />- <!--The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm"/> <error statusCode="404" redirect="FileNotFound.htm"/> </customErrors>
-->< add tagPrefix =" asp " namespace =" System.Web.UI " assembly =" System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />< add tagPrefix =" asp " namespace =" System.Web.UI.WebControls " assembly =" System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " /></ controls ></ pages >< remove verb =" * " path =" *.asmx " />< add verb =" * " path =" *.asmx " validate =" false " type =" System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />< add verb =" * " path =" *_AppService.axd " validate =" false " type =" System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />< add verb =" GET,HEAD " path =" ScriptResource.axd " type =" System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " validate =" false " /></ httpHandlers >< add name =" ScriptModule " type =" System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " /></ httpModules ></ system.web >- < compiler language =" c#;cs;csharp " extension =" .cs " warningLevel =" 4 " type =" Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 " >< providerOption name =" CompilerVersion " value =" v3.5 " />< providerOption name =" WarnAsError " value =" false " /></ compiler ></ compilers ></ system.codedom >- <!--The system.webServer section is required for running ASP.NET AJAX under Internet Information Services 7.0. It is not necessary for previous version of IIS.
-->< validation validateIntegratedModeConfiguration =" false " />< remove name =" ScriptModule " />< add name =" ScriptModule " preCondition =" managedHandler " type =" System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " /></ modules >< remove name =" WebServiceHandlerFactory-Integrated " />< remove name =" ScriptHandlerFactory " />< remove name =" ScriptHandlerFactoryAppServices " />< remove name =" ScriptResource " />< add name =" ScriptHandlerFactory " verb =" * " path =" *.asmx " preCondition =" integratedMode " type =" System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />< add name =" ScriptHandlerFactoryAppServices " verb =" * " path =" *_AppService.axd " preCondition =" integratedMode " type =" System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />< add name =" ScriptResource " preCondition =" integratedMode " verb =" GET,HEAD " path =" ScriptResource.axd " type =" System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " /></ handlers ></ system.webServer >< assemblyIdentity name =" System.Web.Extensions " publicKeyToken =" 31bf3856ad364e35 " />< bindingRedirect oldVersion =" 1.0.0.0-1.1.0.0 " newVersion =" 3.5.0.0 " /></ dependentAssembly >< assemblyIdentity name =" System.Web.Extensions.Design " publicKeyToken =" 31bf3856ad364e35 " />< bindingRedirect oldVersion =" 1.0.0.0-1.1.0.0 " newVersion =" 3.5.0.0 " /></ dependentAssembly ></ assemblyBinding ></ runtime >- < service name =" WcfService1.Service1 " behaviorConfiguration =" WcfService1.Service1Behavior " ></ service ></ services >- <!--To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment
-->< serviceMetadata httpGetEnabled =" true " />- <!--To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information
-->< serviceDebug includeExceptionDetailInFaults =" false " /></ behavior ></ serviceBehaviors ></ behaviors ></ system.serviceModel ></ configuration >Agradeço antecipadamente!
Abraços ,
Eduardo
- Movido Harley AraujoModerator quarta-feira, 7 de abril de 2010 17:03 (De:ASP .NET)
Respostas
-
Boas,
Você deve utilizar basicHttpBinding ao invés de wsHttpBinding. Mas isso é um detalhe que você precisa se atentar depois de resolver este problema.
Já tentou configurar o elemento baseAddressPrefixFilters como eu mostrei no artigo, apontando para aquele endereço que você quer acessar o serviço?
http://www.israelaece.com- Sugerido como Resposta AndreAlvesLimaModerator quinta-feira, 3 de junho de 2010 23:17
- Marcado como Resposta AndreAlvesLimaModerator domingo, 13 de junho de 2010 20:04
Todas as Respostas
-
Boas,
Veja se este artigo te ajuda em algo: http://www.israelaece.com/post/Diferentes-HostHeaders-no-IIS.aspx
http://www.israelaece.com -
Opa Israel, obrigado pela resposta.
Então, eu ja tinha lido esse post seu procurando no google, mas eu tentei e não consegui/não intendi muito bem.
Eu estou tentando hospedar na locaweb, e não tenho acesso ao IIS.
O meu serviço WS é um projeto totalmente separado do silverlight.
Será q vc consegue me ajudar?
Obrigado.
-
-
Opa boa noite.
-
Boas,
Mas está tentando consumir um serviço definido como wsHttpBinding no Silverlight?
http://www.israelaece.com -
-
Boas,
Você deve utilizar basicHttpBinding ao invés de wsHttpBinding. Mas isso é um detalhe que você precisa se atentar depois de resolver este problema.
Já tentou configurar o elemento baseAddressPrefixFilters como eu mostrei no artigo, apontando para aquele endereço que você quer acessar o serviço?
http://www.israelaece.com- Sugerido como Resposta AndreAlvesLimaModerator quinta-feira, 3 de junho de 2010 23:17
- Marcado como Resposta AndreAlvesLimaModerator domingo, 13 de junho de 2010 20:04
-
Eduardo,
Alguma novidade quanto a essa sua dúvida?
André Alves de Lima
Visite o meu site: http://andrealveslima.spaces.live.com
Me siga no Twitter: @andrealveslima -
Israel,
sei que já se passaram alguns meses desde que vc colocou essa resposta. Mas fiz questão de colocar essa citação, porque eu estava a praticamente 5 dias com um chamado aberto na Locaweb para tentar identificar o motivo do erro que ocorria quando a minha aplicação windows form consumia o serviço que hospedei lá. O erro que estava acontecendo era: "System.ServiceModel.CommunicationObjectFaultedException: The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state".
Apesar de funcionar perfeitamente bem quando testava local, quando virava para o endpoint do serviço hospedado na Locaweb, dava o erro. O suporte de lá, até o momente em que escrevia esse texto, ainda não havia me dado uma posição. Como não sou de ficar aguardando, comecei a procurar na web alguém que estivesse com o mesmo problema, e acabei parando aqui no fórum. Resolvi escrever esse texto apenas para dizer que você "salvou a pátria", ou seja, fiz o que recomendou acima, trocando o "wsHttpBinding" pelo "basicHttpBinding" e a aplicação conseguiu consumir o serviço.
Você manda muito.
Obrigado.
PS: vou recomendar a galera do suporte da Locaweb que leia os seus artigos. (rsrs)
Segue o trecho dos arquivos de configuração depois de feita a alteração:
Aplicação (cliente)
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IControleDeAcesso" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://pathdoservico/nomeservico.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IControleDeAcesso"
contract="SrvCa.IControleDeAcesso" name="BasicHttpBinding_IControleDeAcesso" />
</client>
</system.serviceModel>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source = |SQL/CE|" />
</connectionStrings>
</configuration>Serviço (WCF):
<system.serviceModel>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://pathdoservico/nomeservico" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
<service name="Servico" behaviorConfiguration="Servico.ServicoAcessoBehavior">
<endpoint
address="http://pathdoservico/nomeservico.svc/"
binding="basicHttpBinding"
contract="Servico.IServico">
</endpoint>
<endpoint
address=""
binding="wsHttpBinding"
contract="Servico.IServico">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Servico.ServicoAcessoBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Grande abraço.
Bruno
-
Boas Bruno,
Este tipo de erro é muito genérico. O melhor seria você habilitar o tracing e tentar encontrar o problema. De qualquer forma, eu já mudaria o seguinte: se você está utilizando o basicHttpBinding, remova o endpoint do wsHttpBinding. Além disso, defina o atributo address para vazio, ficando assim:
<endpoint
address=""
binding="basicHttpBinding"
contract="Servico.IServico">
</endpoint>
http://www.israelaece.com -