2012-07-27 36 views
7

Tôi đang gặp phải sự cố cấu hình WCF. Tôi có một WCF Webservice mà tôi muốn có thể truy cập thông qua một trình duyệt web bằng cách sử dụng các tham số GET (và cuối cùng trong PHP với simplexml_load_file()). Giải pháp Visual Studio của tôi được thiết lập như một dự án WCF Service Library có chứa một giao diện (nơi dịch vụ được định nghĩa), một lớp (nơi dịch vụ được triển khai và một app.config (mặc định). . Dự án Dịch vụ WCF, trong đó có một file .svc (mà chỉ vào lớp học của tôi) và một web.config Giao diện dịch vụ của tôi được thiết kế như thế này:Địa chỉ cấu hình WCFFilter không khớp

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

và App.config của tôi cho thư viện trông như thế này:

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

Và sau đó Web.config của tôi là như sau:

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

Khi tôi cố gắng để chạy dịch vụ của tôi sử dụng http://devrtxengine.myserver/RTXService.svc/GetCountryList tôi kết thúc với các lỗi sau:

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

tôi nghi ngờ rằng có một số loại không phù hợp giữa App.config của tôi và Web.config của tôi, nhưng mỗi thời gian tôi cố gắng để thay đổi một cái gì đó trong Web.config của tôi tôi phá vỡ dịch vụ của tôi thậm chí nhiều hơn nó đã bị hỏng. Có ai có nhiều kinh nghiệm WCF hơn không?

+0

Các app.config cho thư viện phục vụ là không thích hợp - nó sẽ không được sử dụng. Web.config cho Dịch vụ WCF là tệp cấu hình sẽ được thư viện của bạn sử dụng. Bạn gọi dịch vụ bằng cách nào? Bạn có một khách hàng riêng biệt, bạn đang sử dụng một công cụ kiểm tra, vv? – Tim

+0

Tôi đang gọi nó bằng cách nhập URL vào trình duyệt web của tôi (đó là cách tôi cần để dịch vụ có thể làm việc khi hoàn thành), như được hiển thị trong đoạn nhỏ ngay trước thông báo lỗi. 'http: // devrtxengine.myserver/RTXService.svc/GetCountryList' –

+1

Tôi nhận thấy rằng địa chỉ điểm cuối là devrtxengine.telemark, nhưng bạn có listenUri là devrtxengine.myserver. Không chắc đó có phải là lỗi đánh máy hay không hay nó sẽ tạo ra sự khác biệt. Ngoài ra, bạn có thể thử thêm WebHttpBinding vào các hành vi - xem [Giải quyết lỗi cấu hình trong WCF AddressFilter Mismatch] (http://stackoverflow.com/questions/339421/resolving-configuration-error-in-wcf-addressfilter-mismatch) cho một ví dụ. – Tim

Trả lời

3

Tôi nhận thấy rằng địa chỉ điểm cuối là devrtxengine.telemark, nhưng bạn có listenUri là devrtxengine.myserver. Không chắc đó có phải là lỗi đánh máy hay không hay nó sẽ tạo ra sự khác biệt. Ngoài ra, bạn có thể thử thêm WebHttpBinding vào các hành vi - xem Resolving Configuration Error in WCF AddressFilter Mismatch để biết ví dụ.

2

Đây là những gì tôi kiểm tra khi tôi chạy vào lỗi mà:

* 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

Rất vui được trợ giúp! :-) –

+0

Cảm ơn bạn, dan! Tôi đã phải trudge thông qua nhiều ngăn xếp tràn và kết quả tìm kiếm Google nhưng sau khi fussing w/nhiều nút/thuộc tính của web.config của tôi cho một trong khi đề xuất chỉnh sửa của bạn là những người có WCF của tôi làm việc. Cảm ơn! –

+0

Tôi vui mừng vì bạn đã có thể làm cho nó hoạt động. Chúc mừng! –

Các vấn đề liên quan