----------根據其他網友總結
1.在契約接口上添加:[WebInvoke(RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.WrappedRequest)]
2.在實現契約的的服務上添加標記:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
3.配置文件:
<system.serviceModel>
???????? ? <services >
?????????????????? ? <service name="WebApplication1.guo" >
???????? ??????????? <endpoint address="" behaviorConfiguration="DiggServiceBehavior"? binding="webHttpBinding" contract="WebApplication1.Iguo" />
?????????????????? ? </service>
???????? ? </services>
??? <behaviors>
????? <serviceBehaviors>
??????? <behavior name="AllenBehavior">
????????? <serviceMetadata httpGetEnabled="true" />
??????? ??<serviceDebug includeExceptionDetailInFaults="false" />
?????????????????? </behavior>
????? </serviceBehaviors>
????? <endpointBehaviors>
??????????????? <behavior name="DiggServiceBehavior">
???????? ??????????? <enableWebScript/>
???????? ??????? </behavior>
????? </endpointBehaviors>
??? </behaviors>
??? <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
? </system.serviceModel>
4.調用:
<script type="text/javascript">
??????? function guo() {
??????????? $.ajax({
??????????????? url: "guo.svc/Show",
??????????????? type: 'post',
??????????????? contentType: 'text/json',
??????????????? data: '{"str":"guozefeng"}',
??????????????? success: function (data) { alert(data.d); },
??????????????? error: function (data) { alert("error"); }
????????????? });
??????? }
??? </script>
-------需要注意的:
ry調用WCF的要點:
?
1. [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
?
2. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
?
3.? binding="webHttpBinding"
?
4. <enableWebScript/>
?
5.? contentType: 'text/json'
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
