0

I have a WCF Rest service that i am try to test with the 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

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

This all works fine from a .net client, but not from the rest client plugin of firefox 400 everytime.

any help is very much appreciated

Don

My Web config File

<?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>
  • Don - just trimmed your signature: http://stackoverflow.com/faq#signatures – Jude Fisher Aug 24 '12 at 14:27
  • @JcFx A simple "Thanks" doesn't hurt and is actually polite. Suggested edits should be substantive improvements addressing multiple issues in the post. – fancyPants Aug 24 '12 at 14:36
  • @JcFx Though the link you provided is also valid, please have a look here: http://meta.stackexchange.com/questions/139830/reject-or-approve-suggested-edits-for-removed-clutter Anyway thank you very much for your commitment to this site. – fancyPants Aug 24 '12 at 14:38
  • @tombom My own "thanks in advance", plus name, was removed from my first post (http://stackoverflow.com/posts/11214301/revisions). Since then I've seen any number of thanks + name sigs removed from other posts. I understood we were not to sign posts at all. I personally think the civility of the site would be improved by allowing signatures, and thank yous, as long as they don't self-promote, but above all think that any rule should be applied consistently. I'll gladly bow to your greater experience in this case. – Jude Fisher Aug 24 '12 at 14:45
  • @JcFx Well, two arguments against removing "thank you"s: 1. It causes unnecessary work for others who review edits 2. Search for "thank" on this site and you can find thousands of questions/answers, so sometimes such edits are just reputation farming. Of course I don't impute this to you. – fancyPants Aug 24 '12 at 15:04
  • @tombom - No imputation taken :) Both your arguments persuade me, but I don't think this rule is being applied in the way you say, at least not consistently, and not by my observation in anything like the majority of cases. Even the accepted answer in the link you pointed to says " If that's the only thing that needs to be changed to make the post better, go ahead and approve the edit." - which seems to encourage removing sigs when they alone need editing. Anyway - this is more discussion than the matter perhaps deserves - I accept your correction, and gladly. – Jude Fisher Aug 24 '12 at 15:08

1 Answers1

0

400 often means wrong Http method. 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?

Also, check this content-type issue: Why does my C# client, POSTing to my WCF REST service, return (400) Bad Request?

Also see if adding RequestFormat = WebMessageFormat.Json to the [WebInvoke] attribute decorating your service method helps. I think this defaults to xml, which is probably what the .NET client sends. http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.requestformat.aspx

Community
  • 1
  • 1
Jude Fisher
  • 11,138
  • 7
  • 48
  • 91
  • Appreciate the response, the link, I am already using application/json. I am using POST because they complex type is being passed in the request body as JSON which is why it does not appear in the UriTemplate? so if i am correct the GET wont work which is why I am not using GET. – Mr Cecil Dooberry Aug 24 '12 at 15:19
  • That's right, you shouldn't use get (it won't work with that configuration). I just wondered if the Firefox client used GET by default? Also, you might post your Web.Config - I think the problem is more likely to be in the Service Configuration than in the implementation. Also - check to see if cross-domain access is enabled: I'm not sure what 'domain' the Firefox test client appears to be calling from, but that's another thing that has given me a 400 error in the past. – Jude Fisher Aug 24 '12 at 15:22
  • posted web config above, the Firefox client default is GET but i had changed to POST. – Mr Cecil Dooberry Aug 24 '12 at 15:40
  • I can't see what's wrong there, but hopefully with that info somebody else will be able to. – Jude Fisher Aug 24 '12 at 15:46
  • One final thought. You might try adding RequestFormat = WebMessageFormat.Json to your WebInvoke attribute – Jude Fisher Aug 24 '12 at 16:24
  • Turns out, I had a spelling mistake in the customer header section in the firefox rest client, i had "contnet-type application/json". i am such a dumb ass at times. Thank you for all your help JcFx. – Mr Cecil Dooberry Aug 24 '12 at 18:26