2012-07-27 13 views
7

Ho problemi di configurazione WCF. Dispongo di un servizio Web WCF a cui desidero accedere tramite un browser Web utilizzando i parametri GET (e eventualmente in PHP con simplexml_load_file()). La mia soluzione di Visual Studio è configurata come progetto della libreria di servizi WCF che contiene un'interfaccia (in cui è definito il servizio), una classe (in cui è implementato il servizio e un'app.config (che era presente per impostazione predefinita). . Progetto di servizio WCF che contiene un file .svc (che punta alla mia classe) e un web.config il mio Service Interface è stato progettato in questo modo:Indirizzo di configurazione WCFDisplay del filtro

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; } 
    } 
} 

e il mio App.config per la biblioteca si presenta così:

<?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> 

E poi il mio web.config è la seguente:

<?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> 

Quando si tenta di eseguire il mio servizio utilizzando http://devrtxengine.myserver/RTXService.svc/GetCountryList io alla fine con il seguente errore:

<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> 

ho il sospetto che ci sia una sorta di disallineamento tra la mia e la mia App.config web.config, ma ogni volta che provo a cambiare qualcosa nel mio Web.config, interrompo il mio servizio ancor più di quanto sia già rotto. Qualcuno con più esperienza WCF ha qualche consiglio?

+0

L'app.config per la libreria del servizio è irrilevante - non verrà utilizzato. Web.config per il servizio WCF è il file di configurazione che verrà utilizzato dalla libreria. Come stai chiamando il servizio? Hai un cliente separato, stai usando uno strumento di test, ecc? – Tim

+0

Lo chiamo digitando l'URL nel mio browser web (che è il modo in cui ho bisogno di un servizio in grado di funzionare una volta completato), come mostrato nel piccolo paragrafo appena prima del messaggio di errore. 'http: // devrtxengine.myserver/RTXService.svc/GetCountryList' –

+1

Ho notato che l'indirizzo del punto finale era devrtxengine.telemark, ma avete listenUri come devrtxengine.myserver. Non sono sicuro che sia un refuso o se farebbe la differenza. Inoltre, puoi provare ad aggiungere WebHttpBinding ai comportamenti - vedi [Risolvere errore di configurazione in WCF AddressFilter Mismatch] (http://stackoverflow.com/questions/339421/resolving-configuration-error-in-wcf-addressfilter-mismatch) per un esempio. – Tim

risposta

3

Ho notato che l'indirizzo del punto finale era devrtxengine.telemark, ma avete listenUri come devrtxengine.myserver. Non sono sicuro che sia un refuso o se farebbe la differenza. Inoltre, puoi provare ad aggiungere WebHttpBinding ai comportamenti - vedi Resolving Configuration Error in WCF AddressFilter Mismatch per un esempio.

2

Ecco quello che posso controllare quando mi imbatto in questo errore:

* 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

Felice di aiutare! :-) –

+0

Grazie, Dan! Ho dovuto arrancare attraverso molti stack overflow e risultati di ricerca di Google, ma dopo aver aggredito w/molti nodi/attributi del mio web.config per un po 'i tuoi suggerimenti di modifica sono stati quelli che hanno permesso al mio WCF di funzionare. Grazie! –

+0

Sono felice che tu sia riuscito a farlo funzionare. Saluti! –

Problemi correlati