我有WCF配置的困境。我有一個WCF Web服務,我希望能夠通過使用GET參數的Web瀏覽器訪問(最終在PHP中使用simplexml_load_file())。我的Visual Studio解決方案被設置爲一個WCF服務庫項目,其中包含一個接口(其中服務已定義),一個類(實現服務的地方和一個app.config(默認情況下))。 。WCF服務項目,該項目包含一個.svc文件(這點上我的課)和一個web.config我的服務接口的設計是這樣的:WCF配置AddressFilter不匹配
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}®ionID={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; }
}
}
我的App.config中的庫看起來是這樣的:
<?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>
然後我的web.config如下:
<?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>
當我嘗試使用http://devrtxengine.myserver/RTXService.svc/GetCountryList
我結束了以下錯誤來運行我的服務:
<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>
我懷疑有某種我的App.config和我的web.config之間的不匹配,但每當我嘗試改變Web.config中的某些內容時,我的服務甚至比已經損壞的更多。有更多WCF經驗的人有任何建議嗎?
爲服務庫的app.config是無關緊要的 - 它不會被使用。 WCF服務的Web.config是將由庫使用的配置文件。你打電話的服務怎麼樣?你有一個單獨的客戶端,你是否使用測試工具等? – Tim 2012-07-27 19:30:16
我正在通過在我的Web瀏覽器中輸入URL來調用它(這是我需要服務的時候才能夠在完成時工作),如錯誤消息之前的小段落所示。 'http:// devrtxengine.myserver/RTXService.svc/GetCountryList' – 2012-07-27 19:52:59
我注意到端點地址是devrtxengine.telemark,但是你有listenUri作爲devrtxengine.myserver。不知道這是否是一個錯字,或者它是否會有所作爲。此外,您可以嘗試將WebHttpBinding添加到行爲 - 請參閱[解決WCF AddressFilter不匹配中的配置錯誤](http://stackoverflow.com/questions/339421/resolving-configuration-error-in-wcf-addressfilter-mismatch)for一個例子。 – Tim 2012-07-27 22:27:56