2015-06-06 4 views
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 со следующими файлами.

Service Interface

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

Внедрение Service

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> 

Ive смотрел это вверх и я гавань нашел ничего, чтобы решить эту проблему. Любая помощь будет оценена по достоинству.

+0

Попробуйте удалить атрибут OperationContract и просто покиньте WebGet. Наличие обоих избыточных и может вызвать конфликт. – Crowcoder

+0

@Crowcoder Я попробовал ваше предложение и отредактировал сообщение соответственно. Я по-прежнему получаю такую ​​же ошибку. Я прочитал еще одну статью о том, что мне нужна настройка endPoint в моем web.Config, но не уверен, что это является причиной проблемы. Может ли быть настройка в IIS, которую мне нужно настроить? – zic10

+0

Я действительно не могу быть уверен. Конфигурация WCF может быть медведем. Только другое предложение было бы присвоить имя вашему поведению и поместить это имя в атрибут поведения поконфигурации конечной точки вместо «" – Crowcoder

ответ

0

Понял, довольно простой, но, надеюсь, это поможет любому, кто столкнется с этим в будущем.

<?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="DummyService.Service1" behaviorConfiguration=""> 
     <endpoint 
      address="" 
      binding="webHttpBinding" 
      contract="DummyService.IService1" 
      behaviorConfiguration="Web"> 


     </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> 
     <endpointBehaviors> 
     <behavior name="Web"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
    </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> 

под конечную точку службы, добавляющий behaviorConfiguration = «Web», а затем поведение конечной точки «Web» является то, что исправили проблему.

Смежные вопросы