views:

16

answers:

1

So I am calling a wcf webservice using Rest WebHttp. I also have set up a second binding mex for testing. My method is working but when I try to test through fiddler or straight httppost through a client app I get a 400 Bad request error. I am passing mutliple datacontracts to the method. It forces me to use the BodyStyle of wrapped but I don't know how to format my xml for the test. I have created a test method to try this out and same error. Here is my code: All my other methods work with one datacontract but this one where I have two doesn't. I beleive the issue is in the xml at the bottom of this post, it needs to be wrapped but I do not know how to wrap it.

[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped)]
string Test(wsAuth a, wsMed m);

[DataContract(Namespace = "")]
public class wsMed
{
 [DataMember]
 public string Test{ get; set; }
}

[DataContract(Namespace = "")]
public class wsAuth
{
 [DataMember]
 public string UserName { get; set; }
 [DataMember]
        public string Password { get; set; }
 [DataMember]
 public string DeviceId { get; set; }
}

my xml that I am using

<Test>
<wsAuth>
 <DeviceId>jenglish</DeviceId>
 <Password>treetop</Password>
 <UserName>jenglish</UserName>
</wsAuth>
<wsMed>
 <Test></Test>
</wsMed>
</Test>
+1  A: 

I'm afraid you are going to struggle with this. First off, you are missing the DataContract serialization namespaces. The DataContractSerializer is pretty picky about how it wants it's xml formated.

There was a question just recently from someone trying to do something much simpler and he was having difficulty getting WCF to accept it.

Here is a an explanation of how to format wrapped parameters.

Darrel Miller
Hey Darrel, thanks so much for the advice and pointing me to a couple good posts. I got it to work , I kept the namespaces as "" but my methods were passing a and m as paramater names so the following works now:<Test><a> <DeviceId>jenglish</DeviceId> <Password>treetop</Password> <UserName>jenglish</UserName></a><m> <Test></Test></m></Test>
Carter
@Carter Good luck. You'll need it ;-)
Darrel Miller