【发布时间】:2015-07-07 04:31:45
【问题描述】:
我有一个 WCF 服务,可以将客户保存到数据库中,并且在 Internet Explorer 中按预期工作,但在 Chrome 中不是(因此我将省略 HTML /Json,因为它让我认为这是一个网络配置问题,但如果有人喜欢,我可以发布)。
在 Chrome 中我得到错误:
加载资源失败:服务器响应状态为 405(不允许方法) Subscriber.htm:1 XMLHttpRequest 无法加载 http://example.com/MyService.svc/SaveCustomer。 HTTP 状态码 405 无效
我的网络配置:
<system.web>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
<pages>
<namespaces>
<add namespace="System.Runtime.Serialization" />
<add namespace="System.ServiceModel" />
<add namespace="System.ServiceModel.Web" />
</namespaces>
</pages>
</system.web>
<system.serviceModel>
<services>
<service name="IService.MyService">
<endpoint address="http://example.com/MyService.svc"
binding="webHttpBinding"
bindingConfiguration=""
contract="IService"
behaviorConfiguration="webHttpBinding" />
</service>
</services>
<client>
<endpoint
binding="webHttpBinding"
bindingConfiguration=""
address="http://example.com/MyService.svc"
contract="IService" />
</client>
<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>
<endpointBehaviors>
<behavior name="webHttpBinding">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<httpProtocol>
<customHeaders>
<!-- Enable Cross Domain AJAX calls -->
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Authorization, Accept, X-Requested-With" />
<add name="Access-Control-Allow-Methods" value="OPTIONS, TRACE, GET, HEAD, POST, PUT" />
</customHeaders>
</httpProtocol>
</system.webServer>
所以我阅读了几篇文章并添加了相关部分,删除了 WebDav,但似乎没有任何区别。
【问题讨论】:
-
此链接可能对您有所帮助-
stackoverflow.com/questions/18825458/…
标签: .net wcf google-chrome wcf-binding