2011-02-03 35 views
6

EDITAR: Resumen: Parece que mi aplicación web puede ser accedida por cualquier persona (solo Firefox o Chrome) y por mí utilizando mi computadora principal. Si trato de acceder a http://luiscarlosch.com/WebFormClean.aspx desde cualquier otra de mi LAN, aparece un error 405405: Método no permitido

Puedo llamar perfectamente un método web WCF desde localhost. Publiqué en este servidor: http://luiscarlosch.com/WebFormClean.aspx (solo Firefox o Chrome) con la herramienta de publicación Visual Studio y funciona bien. El problema es cuando intentas acceder desde otra computadora. Obtengo el 405: Método no permitido. Pero tiene sentido porque funciona bien cuando accedo a él de forma remota desde la computadora del editor, como dije. ¿Alguna idea?

[ServiceContract(Namespace = "")] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class ContactProxy 
{ 
    [WebGet()] 
    [OperationContract] 
    public Contact getByID(int IDContact) 
    { 
     Contact contact = new Contact(IDContact); 
     return contact; 
    } 
    [OperationContract] 
    public EntityData insertEntityData(int IDEntityDataFieldType, int IDContact, String value) 
    { 
     //Contact contact = new Contact(); 
     // contact.insertEntityData(IDEntityDataFieldType, IDContact, value); 
     EntityData entityData = new EntityData(); 
     entityData.save(IDEntityDataFieldType, IDContact, value); 

     return entityData; 
    } 
} 

Ninguno de los dos métodos parece funcionar.

Acabo de notar que algunos usuarios pudieron acceder a http://luiscarlosch.com/WebFormClean.aspx porque cambian los valores. Asi que. algunos clientes pueden leer los métodos pero algunos no pueden. Esto debería estar sucediendo.

Web Config

<?xml version="1.0"?> 

<configuration> 
    <configSections> 
    </configSections> 
    <connectionStrings> 
    <add name="ApplicationServices" 
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <customErrors mode="Off"/> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login.aspx" timeout="2880" /> 
    </authentication> 
    <membership> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" 
      enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" 
      maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" 
      applicationName="/" /> 
     </providers> 
    </membership> 
    <profile> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> 
     </providers> 
    </profile> 
    <roleManager enabled="false"> 
     <providers> 
     <clear/> 
     <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /> 
     <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> 
     </providers> 
    </roleManager> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="MyServiceTypeBehaviors" > 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="WebApplicationTest.WCFProxy.EmployeeProxyAspNetAjaxBehavior"> 
      <enableWebScript /> 
     </behavior> 
     <behavior name="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxyAspNetAjaxBehavior"> 
      <enableWebScript /> 
     </behavior> 
     <behavior name="WebApplicationTest.WCFProxy.Service1AspNetAjaxBehavior"> 
      <enableWebScript /> 
     </behavior> 
     <behavior name="WebApplicationTest.WCFProxy.ContactProxyAspNetAjaxBehavior"> 
      <enableWebScript /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="WebApplicationTest.WCFProxy.EmployeeProxy" behaviorConfiguration="MyServiceTypeBehaviors" > 
     <endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.EmployeeProxyAspNetAjaxBehavior" 
      binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.EmployeeProxy" /> 
     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 
     </service> 
     <service name="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxy" behaviorConfiguration="MyServiceTypeBehaviors" > 
     <endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxyAspNetAjaxBehavior" 
      binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.EntityDataFieldCollectionProxy" /> 
     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 
     </service> 
     <service name="WebApplicationTest.WCFProxy.Service1"> 
     <endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.Service1AspNetAjaxBehavior" 
      binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.Service1" /> 
     </service> 
     <service name="WebApplicationTest.WCFProxy.ContactProxy" behaviorConfiguration="MyServiceTypeBehaviors" ><!--new--> 
     <endpoint address="" behaviorConfiguration="WebApplicationTest.WCFProxy.ContactProxyAspNetAjaxBehavior" 
      binding="webHttpBinding" contract="WebApplicationTest.WCFProxy.ContactProxy" /> 
     <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> 
     </service> 
    </services> 
    <bindings /> 
    <client /> 
    </system.serviceModel> 
</configuration> 
+0

¿Es el servicio REST? Necesitamos más información (contrato, configuración, etc.) ... –

+0

Thankx. Acabo de publicar algo más de información. –

+0

Parece que IIS bloquea solicitudes POST (u otras). – leppie

Respuesta

1

el fin de permitir ajax dominios llama necesita

1) en primer lugar para configurar el servidor web para permitir a los orígenes y las cabeceras 2) permitir que los métodos utilizados para hacer la solicitud

es parece que usted ha logrado el primer punto y tal vez para la segunda sólo tiene que cambiar:

[WebGet()] 

a:

[WebInvoke(Method = "*")] 
  • ya que si bien se realiza una solicitud POST o GET.Chrome y Firefox siempre envían OPCIONES
+0

Esto realmente funcionó para mí. IE11 también envía OPCIONES para solicitudes de comprobación previa de CORS – ohmusama

0

Algo extraño está sucediendo en su servicio. En primer lugar, creo que insertEntityDate no debe ser invocable porque falta el atributo WebGet o WebInvoke. Otra cosa extraña es que getById se define como WebGet pero se llama como la solicitud POST JSON - Acabo de comprobar con quemador, y la violinista:

POST http://luiscarlosch.com/WCFProxy/ContactProxy.svc/getByID HTTP/1.1 
Host: luiscarlosch.com 
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.16) Gecko/20101130 Firefox/3.5.16 (.NET CLR 3.5.30729; .NET4.0E) 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-gb,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Proxy-Connection: keep-alive 
X-Requested-With: XMLHttpRequest 
Content-Type: application/json; charset=utf-8 
Referer: http://luiscarlosch.com/WebFormClean.aspx 
Content-Length: 15 
Cookie: ASP.NET_SessionId=puzd3ulsj4em4ufd21b4lkjr 
Pragma: no-cache 
Cache-Control: no-cache 

{"IDContact":1} 

El servicio funciona para mí, pero no es el mismo servicio descrito por contrato nos lo has mostrado. Por cierto. no hay ninguna razón para habilitar el comportamiento de serviceMetadata y agregar puntos finales Mex si no va a usar también el punto final SOAP.

0

Cuando se utiliza CORS, la especificación exige que los navegadores "comprueben previamente" la solicitud, solicitando los métodos admitidos del servidor con HTTP OPTIONS y el servidor envía una respuesta no permitida al método 405, que también indica el método permitido.

El único propósito de esta respuesta es ayudarlo a encontrar las opciones de comunicación disponibles para un recurso URL específico. Permite al cliente determinar las opciones y/o requisitos asociados con un recurso, o las capacidades de un servidor, sin una acción específica que implique la transferencia de datos.

creo que sirve,

0
<system.webServer> 
<handlers> 
<remove name="WebDAV" /> 
     <add name="RestProxy32" path="Service.svc" verb="*" modules="IsapiModule" 
      scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" 
      preCondition="classicMode,runtimeVersionv2.0,bitness32"/> 
     <add name="RestProxy64" path="Service.svc" verb="*" modules="IsapiModule" 
      scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" 
      preCondition="classicMode,runtimeVersionv2.0,bitness64"/> 
</handlers> 
<modules> 
<remove name="WebDAVModule" /> 
</modules> 

</system.webServer> 
Cuestiones relacionadas