简体   繁体   中英

Wcf method strange behaviour

I have built a WCF service which I am consuming with android client. I had this method:

    [WebInvoke(
        Method = "POST",
        UriTemplate = "syncfromserver/",
        BodyStyle = WebMessageBodyStyle.Bare,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    Message SyncFromServer(LocalDatabaseModel tc);

and it was working perfectly. Then I needed to send another parameter to the Method and I edited it like this:

    [WebInvoke(
        Method = "POST",
        UriTemplate = "syncfromserver/token={token}",
        BodyStyle = WebMessageBodyStyle.Bare,
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json)]
    Message SyncFromServer(string token, LocalDatabaseModel tc);

when I tried i kept getting errors, so I wanted to come to the previous working version, but now it wont work !? I have deleted all changes but it seems that the server is remembering them somehow and I keep getting 405 error, "HTTP verb used to access this page is not allowed". Any help, someone ?

I have solved this by making a data contract class like this:

[DataContract]
public class CombinedObject{
       [DataMember(Name="token")]
       public string token {get; set; }    
       [DataMember(Name="model")]
       public LocalDatabaseModel model {get; set; }    

}

and the same class on client side, to respect the contract. After that the WCF method was:

   [WebInvoke(
    Method = "POST",
    UriTemplate = "syncfromserver/",
    BodyStyle = WebMessageBodyStyle.Bare,
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json)]
    Message SyncFromServer(CombinedObject tc);

and everything worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM