Pregunta

Hemos tratado de utilizar un servicio WCF muy muy simple con un HTTP GET y no lo puede operar. Hemos seguido los "guía" pero no funciona

Cuando llamamos a nuestro servicio con el siguiente URL, se obtiene un error de página no encontrada:

  

http: // localhost: 9999 / Service1.svc / GetData / ABC

La URL base (http: // localhost: 9999 / Service1.svc). Trabaja muy bien y devuelve la página de información de servicio WCF correctamente

Estos son los pasos y el código para reproducir nuestro ejemplo.

  1. En Visual Studio 2010, cree un nuevo "servicio WCF aplicación" Proyecto
  2. Sustituir la interfaz IService con este código

      [ServiceContract()]
      public interface IService1
      {
          [OperationContract()]
          [WebInvoke(Method = "GET", 
                     BodyStyle = WebMessageBodyStyle.Bare, 
                     UriTemplate = "GetData/{value}")]
          string GetData(string value);
      }
    
  3. Sustituir la clase de servicio con el código

    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
    
  4. La mirada web.config como esto          

    <system.web>
       <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
      <services>
          <service name="Service1">
              <endpoint address="" binding="webHttpBinding" contract="IService1" behaviorConfiguration="WebBehavior1">
              </endpoint>
          </service>
      </services>
      <behaviors>
          <endpointBehaviors>
              <behavior name="WebBehavior1">
                 <webHttp helpEnabled="True"/>
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
    

         

  5. Pulse Ejecutar y tratar de llamar al método get

Si alguien consigue esto o algo similar de trabajo, sería muy amable si pudiera responder información sobre el ejemplo de trabajo.

Muchas gracias

¿Fue útil?

Solución

He recreado su muestra -. Funciona como un encanto

Un punto: hacer su contrato de servicio (public interface IService1) y la implementación del servicio (public class Service1 : IService1) se realiza al interior de un espacio de nombres de .NET ??

Si es así, usted necesita cambiar su * .svc y su web.config incluir:

<services>
      <service name="Namespace.Service1">
          <endpoint address="" binding="webHttpBinding" 
                    contract="Namespace.IService1" 
                    behaviorConfiguration="WebBehavior1">
          </endpoint>
      </service>
  </services>

El atributo <service name="..."> y la <endpoint contract="..."> debe incluir el espacio de nombres de .NET para que esto funcione.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top