【问题标题】:Wcf method strange behaviourWcf 方法奇怪的行为
【发布时间】:2014-03-14 16:41:09
【问题描述】:

我已经构建了一个 WCF 服务,我正在使用 android 客户端。我有这个方法:

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

它运行良好。然后我需要向方法发送另一个参数,然后我像这样编辑它:

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

当我尝试时,我不断收到错误,所以我想回到以前的工作版本,但现在它不能工作了!?我已经删除了所有更改,但似乎服务器以某种方式记住了它们,并且我不断收到 405 错误,“不允许用于访问此页面的 HTTP 动词”。有人帮忙吗?

【问题讨论】:

标签: c# wcf


【解决方案1】:

我通过制作这样的数据合约类解决了这个问题:

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

}

和客户端相同的类,尊重合同。之后 WCF 方法是:

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

一切正常。

【讨论】:

    猜你喜欢
    • 2012-07-13
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    相关资源
    最近更新 更多