方法不允许wcf休息与类型发布

时间:2012-08-24 14:00:12

标签: jquery json wcf rest

我使用wcf创建了一个应用程序并且休息了我的操作问题我使用Type Post他不允许retun方法,这是我的操作

[WebInvoke(Method = "POST", UriTemplate = "newContact", ResponseFormat = WebMessageFormat.Json)]
        [AuthorizedMethod]
        bool CreateContact(string jsonstring);

并在此页面中我将类型字符串转换为json

public bool CreateContact(string jsonstring)
        {
            Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonstring);

            log();
            return dispatcher.CreateContact(values);

这是我的服务

<system.serviceModel>
    <services>
      <service behaviorConfiguration="Default" name="Mobility.SolutionService.AppService">
        <host>
          <baseAddresses>          
            <add baseAddress="https://localhost:443/B2M/"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="crossDomain" 
                  contract="Mobility.SolutionService.IAppService" behaviorConfiguration="Web"/>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
      <binding name="crossDomain">

          <security mode="Transport">
            <transport clientCredentialType="Basic" >
            </transport>
          </security>
        </binding> 
      </webHttpBinding>
      </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
         <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpsGetEnabled="true" />
         <serviceCredentials>

           <userNameAuthentication userNamePasswordValidationMode="Custom"
                                    customUserNamePasswordValidatorType="Mobility.SolutionService.CustomUserNamePasswordValidator, Mobility.SolutionService"/>
           <serviceCertificate findValue="CN=AuthorityName"/>
          </serviceCredentials>

          <serviceAuthorization principalPermissionMode="Custom">
             <authorizationPolicies>
              <add policyType="Mobility.SolutionService.CustomAuthorizationPolicy, Mobility.SolutionService"/>
            </authorizationPolicies> 
          </serviceAuthorization>

        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

然后我用js发送数据

function CreateClient(button){
var strN = document.getElementById('nom').value;
        var str1 = document.getElementById('Phone').value;
        var str2 = document.getElementById('Address').value;
        var str10 = document.getElementById('Credit_Limit_LCY').value;
        var dict = []; 
dict.push(
{
       key:"nom",
       value: strN
},
{
        key:"Phone",
        value:str1
},
{
        key: "Address",
        value:str2
},
{
key:"Credit_Limit_LCY",
value:str10
}
);
var Mydata=JSON.stringify(dict);
$.mobile.showPageLoadingMsg();
var geturl;

  geturl =$.ajax({  
 url:"https://10.0.2.2:443/B2M/newContact/",
  data:Mydata,
  contentType:"application/json; charset=utf-8",
   dataType:"json",
   timeout:10000000,  
   cache:false,
   type:'POST',
  beforeSend : function(req) {
             req.setRequestHeader('Authorization', 
                   make_base_auth (val1,val2));
        },
   error:function(XMLHttpRequest,textStatus, errorThrown) { 
   $.mobile.hidePageLoadingMsg();   

    alert("Error status :"+textStatus);  
     alert("Error type :"+errorThrown);  
     alert("Error message :"+XMLHttpRequest.responseXML);  

   },   
success:function(data) {
   alert("success");
   $.mobile.hidePageLoadingMsg();
    $.mobile.changePage("contact.html", "fade");
   }
});
   }
你能帮我吗? 感谢

1 个答案:

答案 0 :(得分:0)

我会看一下以下网址REST guide

缺少多个REST属性,您应该使用对象而不是表示json对象的字符串化字符串。在服务器上,框架负责处理。