Ho lavorato in .NET per un po 'di tempo, ma sono nuovo a WCF. Sto cercando di creare il mio primo servizio WCF usando JSON. Pensavo che avrei iniziato davvero, molto semplice e poi costruito da lì. Ma in qualche modo sono riuscito a rovinare anche i servizi più semplici. Ecco cosa ho ottenuto finora.WCF Json GET Servizio: Verificare che il mittente e il destinatario EndpointAddresses siano d'accordo
Web.Config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="MarathonInfo.MarathonInfoService">
<endpoint address="http://localhost:10298/MarathonInfoService.svc" binding="webHttpBinding" contract="MarathonInfo.IMarathonInfo" />
</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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Poi, nel file di servizio:
namespace MarathonInfo
{
public class MarathonInfoService : IMarathonInfo
{
public String GetData()
{
return "Hello World";
}
}
}
E nell'interfaccia:
namespace MarathonInfo
{
[ServiceContract]
public interface IMarathonInfo
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
String GetData();
}
}
Così, quando vado a questo URL:
http://localhost:10298/MarathonInfoService.svc/GetData
ottengo questo errore:
The message with To 'http://localhost:10298/MarathonInfoService.svc/GetData' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
sono in grado di eseguire il servizio di bene tramite Visual Studio in modalità debug. Ma nel browser, ottengo solo quell'errore.
Cosa sto sbagliando?
Grazie!
Casey
Grazie! Questo ha fatto il trucco !! – user1418704
Funziona davvero. Grazie. –