ajax post 请求 wcf,Ajax使用POST方式请求WCF的问题,以POST方式报405

[ServiceContract]

public interface IService1

{

[OperationContract, WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "hello/{nie}")]

string DoWork(string nie);

[OperationContract, WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "hello1")]

string DoWork1();

}

//实现

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

public class Service1 : IService1

{

public string DoWork(string nie)

{

return jss.Serialize("hello" + nie);

}

public string DoWork1()

{

return jss.Serialize("hello");

}

}

// 配置文件Webconfig

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<system.webServer>

<!--跨域-->

<httpProtocol>

<customHeaders>

<add name="Access-Control-Allow-Origin" value="*" />

<!--Content-Type,-->

<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />

<add name="Access-Control-Allow-Methods" value="GET,POST,PUT, DELETE, OPTIONS" />

</customHeaders>

</httpProtocol>

<security>

<requestFiltering>

<requestLimits maxQueryString="2147483640" maxUrl="2097151" maxAllowedContentLength="2097151"/>

</requestFiltering>

</security>

</system.webServer>

<system.web>

<compilation debug="true" targetFramework="4.0" />

</system.web>

<system.serviceModel>

<behaviors>

<endpointBehaviors>

<behavior name="webHttp">

<webHttp helpEnabled="true"/>

</behavior>

</endpointBehaviors>

<serviceBehaviors>

<behavior name="MapConfigBehavior">

<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->

<serviceMetadata httpGetEnabled="true"/>

<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->

<serviceDebug includeExceptionDetailInFaults="true"/>

<dataContractSerializer maxItemsInObjectGraph="2147483647"/>

</behavior>

</serviceBehaviors>

</behaviors>

<bindings>

<webHttpBinding>

<binding name="webHttpBindConfig" receiveTimeout="00:30:00" sendTimeout="00:30:00" maxReceivedMessageSize="104857600">

<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"/>

<security mode="None"></security>

</binding>

</webHttpBinding>

</bindings>

<services>

<service name="WCF_POST.Service1" behaviorConfiguration="MapConfigBehavior">

<endpoint address="" binding="webHttpBinding" contract="WCF_POST.IService1" bindingConfiguration="webHttpBindConfig" behaviorConfiguration="webHttp"/>

</service>

</services>

</system.serviceModel>

</configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值