[英]Error posting JSON to WCF Rest Service
I have a WCF Rest service that i am try to test with the Firefox Rest Client, 我有一个WCF Rest服务,我正在尝试使用Firefox Rest Client进行测试,
The signature of the method i am calling is 我正在调用的方法的签名是
[WebInvoke(Method = "POST", UriTemplate = "UploadEvidenceData/{userName}/{password}/{cdb}")]
public EvidenceData UploadEvidenceData(string userName, string password, string cdb, EvidenceData evidence)
The Data Contract for evidence is 数据合同的证据是
[DataContract(Name = "EvidenceData", Namespace = "http://StudentEvidence.com")]
public class EvidenceData
{
[DataMember]
public string LearnerID { get; set; }
[DataMember]
public string UnitID { get; set; }
[DataMember]
public string AssessorID { get; set; }
[DataMember]
public int MethodO { get; set; } //int
[DataMember]
public int MethodEwt { get; set; } //int
[DataMember]
public int MethodEp { get; set; } //int
[DataMember]
public int MethodQc { get; set; } //int
[DataMember]
public int MethodEps { get; set; } //int
[DataMember]
public int MethodPd { get; set; } //int
[DataMember]
public int MethodS { get; set; } //int
[DataMember]
public int MethodEwa { get; set; } //int
[DataMember]
public int MethodEch { get; set; } //int
[DataMember]
public int MethodEwe { get; set; } //int
[DataMember]
public int MethodApel { get; set; } //int
[DataMember]
public int EvidenceID { get; set; } //int
[DataMember]
public string EvidenceFileName { get; set; }
[DataMember]
public int EvidenceFileSize { get; set; } //int
[DataMember]
public string EvidenceDescription { get; set; }
[DataMember]
public string AssessorFeedback { get; set; }
[DataMember]
public string Signature { get; set; }
[DataMember]
public int RequirementID { get; set; } //int
[DataMember]
public int ModuleID { get; set; } //int
public EvidenceData()
{
this.LearnerID = string.Empty;
this.UnitID = string.Empty;
this.AssessorID = string.Empty;
this.MethodO = 0;
this.MethodEwt = 0;
this.MethodEp = 0;
this.MethodQc = 0;
this.MethodEps = 0;
this.MethodPd = 0;
this.MethodS = 0;
this.MethodEwa = 0;
this.MethodEch = 0;
this.MethodEwe = 0;
this.MethodApel = 0;
this.EvidenceID = 0;
this.EvidenceFileName = string.Empty;
this.EvidenceFileSize = 0;
this.EvidenceDescription = string.Empty;
this.AssessorFeedback = string.Empty;
this.Signature = null;
this.RequirementID = 0;
this.ModuleID = 0;
}
}
and when i use the client use the address http://something.com/Service/UploadEvidence/user/pass/mydb 当我使用客户端时,请使用地址http://something.com/Service/UploadEvidence/user/pass/mydb
and in the body i put 在我身上
{"AssessorFeedback":"Nothing to report","AssessorID":"32fac8c2-0f9b-4cad-a2e4-55b06e968da0","EvidenceDescription":"some evidence","EvidenceFileName":"Lighthouse.jpg","EvidenceFileSize":561276,"EvidenceID":0,"LearnerID":"61b9eca6-6c3e-4bd3-8963-69d9ad3e5eeb","MethodApel":0,"MethodEch":0,"MethodEp":0,"MethodEps":0,"MethodEwa":0,"MethodEwe":0,"MethodEwt":0,"MethodO":0,"MethodPd":0,"MethodQc":0,"MethodS":0,"ModuleID":1131,"RequirementID":30476,"Signature":null,"UnitID":"c33ea6e1-ac54-46dc-a512-3a2efafd5a0b"}
and i have custom header of application/json 而且我有application / json的自定义标头
This all works fine from a .net client, but not from the rest client plugin of firefox 400 everytime. 所有这些都可以从.net客户端正常运行,但不能每次都从firefox 400的其余客户端插件正常运行。
any help is very much appreciated 很感谢任何形式的帮助
Don 唐
My Web config File 我的Web配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name=""
helpEnabled="true"
automaticFormatSelectionEnabled="true"
defaultOutgoingResponseFormat="Json"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
transferMode="Buffered" />
</webHttpEndpoint>
</standardEndpoints>
<services></services>
</system.serviceModel>
</configuration>
400 often means wrong Http method. 400通常意味着错误的Http方法。 Does the Firefox client use GET (which would require a different attribute on your method, and a tweak to your web.config to allow web get), or are you certain it's POST?
Firefox客户端是否使用GET(这将要求您的方法使用不同的属性,并对Web.config进行调整以允许Web获取),或者确定是POST?
Also, check this content-type issue: Why does my C# client, POSTing to my WCF REST service, return (400) Bad Request? 此外,请检查此内容类型问题: 为什么我的C#客户端(发布到WCF REST服务)过后返回(400)错误请求?
Also see if adding RequestFormat = WebMessageFormat.Json
to the [WebInvoke]
attribute decorating your service method helps. 另请参阅是否将
RequestFormat = WebMessageFormat.Json
添加到[WebInvoke]
属性以装饰服务方法是否[WebInvoke]
帮助。 I think this defaults to xml, which is probably what the .NET client sends. 我认为这默认为xml,这可能是.NET客户端发送的内容。 http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.requestformat.aspx
http://msdn.microsoft.com/zh-CN/library/system.servicemodel.web.webinvokeattribute.requestformat.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.