2012-07-27 10 views
7

Estoy teniendo problemas de configuración WCF. Tengo un servicio web WCF al que quiero poder acceder a través de un navegador web usando los parámetros GET (y eventualmente en PHP con simplexml_load_file()). Mi solución de Visual Studio está configurada como un proyecto de biblioteca de servicios WCF que contiene una interfaz (donde se define el servicio), una clase (donde se implementa el servicio y un app.config (que estaba allí por defecto). También tengo un . Proyecto de servicio WCF que contiene un archivo .svc (que apunta a mi clase) y un web.config mi interfaz de servicio está diseñado de esta manera:Configuración WCF AddressFilter no coincide

using System; 
using System.Collections.Generic; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Web; 
using RTXEngineLib.externalLibrary; 
namespace RTXEngineLib { 
    [ServiceContract(Name = "RTXEngine", Namespace = "")] 
    public interface IRTXEngine { 
     [OperationContract(Name = "GetCountryList"), WebGet(UriTemplate = "/GetCountryList/", ResponseFormat = WebMessageFormat.Xml)] 
     List<Country> GetCountryList(); 
     [OperationContract(Name = "GetRegions"), WebGet(UriTemplate = "/GetRegions/?countryID={countryID}", ResponseFormat = WebMessageFormat.Xml)] 
     List<Region> GetRegions(int countryID); 
     [OperationContract(Name = "GetExchangeAvailability"), WebGet(UriTemplate = "/GetExchangeAvailability/?countryID={countryID}&month={month}&year={year}&regionID={regionID}&resortID={resortID}", ResponseFormat = WebMessageFormat.Xml)] 
     AvailabilityList GetExchangeAvailability(int countryID, String month, int year, String regionID = "?", String resortID = ""); 
     [OperationContract(Name = "GetResortsForDate"), WebGet(UriTemplate = "/GetResortsForDate/?month={month}&year={year}", ResponseFormat = WebMessageFormat.Xml)] 
     List<AvailabilityList> GetResortsForDate(String month, int year); 
     [OperationContract(Name = "GetRegionLists"), WebGet(UriTemplate = "/GetRegionLists/", ResponseFormat = WebMessageFormat.Xml)] 
     List<RegionList> GetRegionLists(); 
     [OperationContract(Name = "GetRegionListCacheState"), WebGet(UriTemplate = "/GetRegionListCacheState/", ResponseFormat = WebMessageFormat.Xml)] 
     Boolean GetRegionListCacheState(); 
    } 
    [DataContract(Namespace = "")] 
    public class LoginRequestResponse { 
     [DataMember] 
     public Boolean Success { get; set; } 
     [DataMember] 
     public AccountStanding AccountStanding { get; set; } 
     [DataMember] 
     public double FTXBalance { get; set; } 
     [DataMember] 
     public List<User> Users { get; set; } 
     [DataMember] 
     public List<ContractData> Contracts { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public enum AccountType { 
     [DataMember] 
     NonAuthenticatedAccount, 
     [DataMember] 
     AC, 
     [DataMember] 
     PT, 
     [DataMember] 
     Wks 
    } 
    [DataContract(Namespace = "")] 
    public enum AccountStanding { 
     [DataMember] 
     NotAuthenticated, 
     [DataMember] 
     Good, 
     [DataMember] 
     Mixed, 
     [DataMember] 
     Delinquent 
    } 
    [DataContract(Namespace = "")] 
    public struct RegionList { 
     [DataMember] 
     public String CountryName { get; set; } 
     [DataMember] 
     public String CountryID { get; set; } 
     [DataMember] 
     public List<Region> Regions { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public struct Country { 
     [DataMember] 
     public String CountryName { get; set; } 
     [DataMember] 
     public String ID { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public struct Region { 
     [DataMember] 
     public String RegionName { get; set; } 
     [DataMember] 
     public String ID { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public struct User { 
     [DataMember] 
     public String FirstName { get; set; } 
     [DataMember] 
     public String LastName { get; set; } 
     [DataMember] 
     public String Address { get; set; } 
     [DataMember] 
     public String City { get; set; } 
     [DataMember] 
     public String State { get; set; } 
     [DataMember] 
     public String Zip { get; set; } 
     [DataMember] 
     public String CountryOfResidence { get; set; } 
     [DataMember] 
     public String PhoneNumber { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public struct ContractData { 
     [DataMember] 
     public String ContractID { get; set; } 
     [DataMember] 
     public AccountType AccountType { get; set; } 
     [DataMember] 
     public AccountStanding AccountStanding { get; set; } 
     [DataMember] 
     public String AvailablePoints { get; set; } 
     [DataMember] 
     public String UnavailablePoints { get; set; } 
     [DataMember] 
     public String Usage { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public struct PointsData { 
     [DataMember] 
     public String ContractID { get; set; } 
    } 
    [DataContract(Namespace = "")] 
    public class GlobalAppCache { 
     [DataMember] 
     public static DateTime RegionListsLastUpdate { get; set; } 
     [DataMember] 
     public static List<RegionList> CachedRegionLists { get; set; } 
    } 
} 

y mi App.config para la biblioteca es el siguiente:

<?xml version="1.0"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5555555555555555"> 
     <section name="RTXEngineLib.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> 
    </sectionGroup> 
    </configSections> 
    <system.web> 
    <compilation debug="true"/> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's 
    app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service name="RTXEngineLib.RTXEngineLib"> 
     <endpoint address="" binding="wsHttpBinding" contract="RTXEngineLib.IRTXEngineLib"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/RTXEngineLib/RTXEngineLib/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- 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> 
    <applicationSettings> 
    <RTXEngineLib.Properties.Settings> 
     <setting name="RTXEngineLib_externalLibrary" serializeAs="String"> 
     <value>http://externalLibrary.com/websvcs/externalLibrary.asmx</value> 
     </setting> 
    </RTXEngineLib.Properties.Settings> 
    </applicationSettings> 
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> 

Y entonces mi Web.config es el siguiente:

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="Web" sendTimeout="00:03:00" maxBufferSize="131072" 
      maxReceivedMessageSize="131072" /> 
     </webHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="Basic" name="RTXEngineLib.RTXEngineLib"> 
     <endpoint address="http://devrtxengine.telemark/RTXService.svc" 
      binding="webHttpBinding" bindingConfiguration="Web" name="Basic" 
      contract="RTXEngineLib.IRTXEngine" listenUri="http://devrtxengine.myserver/RTXService.svc" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     <behavior name="Basic"> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     <behavior name="Web"> 
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" 
      httpGetBindingConfiguration="" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

Cuando intento ejecutar mi servicio utilizando http://devrtxengine.myserver/RTXService.svc/GetCountryList termino con el siguiente error:

<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"> 
<Code> 
<Value>Sender</Value> 
<Subcode> 
<Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:DestinationUnreachable</Value> 
</Subcode> 
</Code> 
<Reason> 
<Text xml:lang="en-US"> 
The message with To 'http://devrtxengine.telemark/RTXService.svc/GetCountryList' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree. 
</Text> 
</Reason> 
</Fault> 

Sospecho que hay algún tipo de desajuste entre mi y mi App.config Web.config, pero cada vez que intento cambiar algo en mi Web.config, rompo mi servicio incluso más de lo que ya está roto. ¿Alguien con más experiencia en WCF tiene algún consejo?

+0

El app.config para la biblioteca servicio es irrelevante - no va a ser utilizado. El Web.config para el Servicio WCF es el archivo de configuración que usará su biblioteca. ¿Cómo llamas el servicio? ¿Tiene un cliente separado, está usando una herramienta de prueba, etc.? – Tim

+0

Lo estoy llamando escribiendo la URL en mi navegador web (que es la forma en que necesito servicio capaz de trabajar cuando se complete), como se muestra en el pequeño párrafo justo antes del mensaje de error. 'http: // devrtxengine.myserver/RTXService.svc/GetCountryList' –

+1

Noté que la dirección del punto final era devrtxengine.telemark, pero tiene el listenUri como devrtxengine.myserver. No estoy seguro de si es un error tipográfico o si marcaría la diferencia. Además, puede intentar agregar WebHttpBinding a los comportamientos; consulte [Resolución de errores de configuración en WCF AddressFilter Mismatch] (http://stackoverflow.com/questions/339421/resolving-configuration-error-in-wcf-addressfilter-mismatch) para un ejemplo. – Tim

Respuesta

3

Me di cuenta de que la dirección del punto final era devrtxengine.telemark, pero tiene el listenUri como devrtxengine.myserver. No estoy seguro de si es un error tipográfico o si marcaría la diferencia. Además, puede intentar agregar WebHttpBinding a los comportamientos; consulte Resolving Configuration Error in WCF AddressFilter Mismatch para ver un ejemplo.

2

Esto es lo que puedo comprobar cuando corro en ese error:

* endpoint is missing in web.config, 
* doublecheck the UriTemplate path 
* make sure to set an endpointBehavior inside behaviors, such as 
    <endpointBehaviors> 
    < behavior name =" web" > 
     < webHttp /> 
    </ behavior > 
    </ endpointBehaviors > 
* and set behaviorConfiguration="web" on endpoint your individual endpoint 
+0

¡Feliz de ayudar! :-) –

+0

Gracias, Dan! Tuve que recorrer muchos desbordamientos de pila y resultados de búsqueda de Google, pero después de preocuparme por muchos nodos/atributos de mi web.config durante un tiempo, sus sugerencias de edición fueron las que lograron que mi WCF funcionara. ¡Gracias! –

+0

Me alegra que pudieras hacerlo funcionar. ¡Aclamaciones! –

Cuestiones relacionadas