servicio restful paso net example crear con json wcf get endpoint

json - restful - wcf rest service



WCF Json GET Service: compruebe que EndpointAddresses del emisor y del receptor estén de acuerdo (1)

He estado trabajando en .NET desde hace un tiempo, pero soy nuevo en WCF. Intento crear mi primer servicio WCF usando JSON. Pensé que comenzaría muy, muy simple y luego construiría desde allí. Pero de alguna manera he logrado arruinar incluso los servicios más simples. Esto es lo que tengo hasta ahora.

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>

Luego, en el archivo de servicio:

namespace MarathonInfo { public class MarathonInfoService : IMarathonInfo { public String GetData() { return "Hello World"; } } }

Y en la interfaz:

namespace MarathonInfo { [ServiceContract] public interface IMarathonInfo { [OperationContract] [WebInvoke(Method = "GET", UriTemplate = "/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] String GetData(); } }

Entonces, cuando voy a esta url:

http://localhost:10298/MarathonInfoService.svc/GetData

Me sale este error:

El mensaje con A ''http: // localhost: 10298 / MarathonInfoService.svc / GetData'' no puede procesarse en el receptor, debido a una falta de coincidencia de AddressFilter en el EndpointDispatcher. Verifique que EndpointAddresses del emisor y el receptor estén de acuerdo.

Puedo ejecutar el servicio muy bien a través de Visual Studio en modo de depuración. Pero en el navegador, solo obtengo ese error.

¿Qué estoy haciendo mal?

¡Gracias!

Casey


Si desea crear un punto final WCF WebHTTP (es decir, uno que devuelva JSON y utilice los atributos [WebGet] / [WebInvoke]), el punto extremo debe tener asociado el comportamiento <webHttp/> .

<system.serviceModel> <services> <service name="MarathonInfo.MarathonInfoService"> <endpoint address="http://localhost:10298/MarathonInfoService.svc" binding="webHttpBinding" contract="MarathonInfo.IMarathonInfo" behaviorConfiguration="Web"/> </service> </services> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="Web"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="false" /> </system.serviceModel>