0
當我嘗試從瀏覽器中的wcf服務中查看其中一種方法時,我收到了此消息。WCF地址不匹配錯誤
The message with To 'http://localhost:55047/Service1.svc/GetMessage' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
我有另一個WCF項目,我在這臺計算機上構建的工作得很好,我可以成功查看瀏覽器中的服務方法。
所以我用下面的文件創建了一個新的WCF服務。
服務接口
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[WebGet(UriTemplate = "/GetMessage")]
string GetMessage();
// TODO: Add your service operations here
}
服務實現
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public string GetMessage()
{
return "Hello from the Get Message Method";
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
的Web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="TestService.Service1" behaviorConfiguration="">
<endpoint address="" binding="webHttpBinding" contract="TestService.IService1" behaviorConfiguration="">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
伊夫看着這了,我還沒有發現任何東西來解決這個問題。任何幫助,將不勝感激。
嘗試刪除OperationContract屬性,然後離開WebGet。兩者都是多餘的,可能會導致衝突。 – Crowcoder
@Crowcoder我嘗試了你的建議,並相應地編輯了這篇文章。我仍然收到相同的錯誤。我讀了另一篇關於在我的web.Config中需要endPoint配置的文章,但不確定這是否是問題的原因。它可能是我需要調整的IIS配置嗎? – zic10
我真的不能確定。 WCF配置可以是一個熊。只有其他建議可以爲您的行爲分配一個名稱,並將該名稱放入端點behaviorConfiguration屬性中,而不是「」 – Crowcoder