WCF Rest Multiple DataContracts Wrapped
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 multiple 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 ha开发者_Go百科ve two doesn't. I believe 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>
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.
精彩评论