C# 获取预飞行在chrome WCF服务中具有无效的HTTP状态代码405
我正在尝试将图像上传到服务器上,它在safari上运行良好,但在chrome上不起作用。我面对这个错误 XMLHttpRequest无法加载“URL”响应,因为飞行前的HTTP状态代码405无效 //接口C# 获取预飞行在chrome WCF服务中具有无效的HTTP状态代码405,c#,.net,web-services,wcf,C#,.net,Web Services,Wcf,我正在尝试将图像上传到服务器上,它在safari上运行良好,但在chrome上不起作用。我面对这个错误 XMLHttpRequest无法加载“URL”响应,因为飞行前的HTTP状态代码405无效 //接口 public interface ISignatureUpload { [OperationContract(Name = "AddEPCRSignUpload")] [WebInvoke(Method = "POST", UriTemplate = "
public interface ISignatureUpload
{
[OperationContract(Name = "AddEPCRSignUpload")]
[WebInvoke(Method = "POST", UriTemplate = "/AddEPCRSignUpload?fileName={fileName}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
string AddEPCRSignUpload(string fileName, string sigFile);
}
//接口实现代码
public class SignatureUpload : ISignatureUpload
{
public string AddEPCRSignUpload(string fileName, string sigFile)
{
// Some Code to upload file
}
}
//Web.Config
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
<system.web>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="SignatureService.WebHttp" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed"
sendTimeout="00:05:00">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="SignatureUpload.Behavior" name="SignatureUpload.SignatureUpload">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="SignatureService.WebHttp" contract="SignatureUpload.ISignatureUpload">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="SignatureUpload.Behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
刚刚将Method=“POST”更改为Method=“*”,立即完成工作刚刚将Method=“POST”更改为Method=“*”,立即完成工作
var imageInspector = document.getElementById("sigcanvas").toDataURL("image/png");
imageInspector = imageInspector.replace('data:image/png;base64,', '');
jQuery.support.cors = true;
$.ajax({
url: 'http://serverip/DCASSigUpload/SignatureUpload.svc/AddEPCRSignUpload?fileName=' + itemID + "~Signature~sigcanvas",
type: 'POST',
//data: '{ "sigFile" : "' + image + '" }',
data: JSON.stringify(imageInspector),
crossDomain:true,
dataType: 'json',
//processData: false, // Don't process the files
contentType: 'application/json; charset=utf-8',
//contentType: "application/octet-stream",
success: function (data) {
//$("#modal-content, #modal-background").toggleClass("active");
alert("Done");
},
error: OnGetAllMembersError
});