Matt Dinovo

Can someone explain to me what would cause the message body to differ from the serialized data contract it's supposed to be returning. I'm writing an app that swaps out pre-canned message bodies. The body is determined by the data contract. As you can see below, what the serialized contract looks like and what the message inspector wrote out as the message body differs. I'm using BasicHttpBinding. Any suggestions on how to get them to look the same

Serialized Contract:

<AddSubscriptionResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org">
<Result>
<success>true</success>
</Result>
</AddSubscriptionResponse>

Message Body:

<AddSubscriberResponse xmlns="http://tempuri.org">
<AddSubscriberResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Result>
<success>true</success>
</Result>
</AddSubscriberResult>
</AddSubscriberResponse>



Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Pablo Cibraro

Hi Matt,

Are you using a Message contract to define the message "AddSuscriberResponse" . If you are using a message contract, there is an attribute "IsWrapped" that can be set to false to avoid the extra element in the message.

Regards,

Pablo.






Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Matt Dinovo

Unfortunately, no. I thought about going the Message Contract route (for the greater control) but I'm writin an app that will generate dummy messages when presented with an XSD, so I'm stuck using Data Contracts.

This much I do know, the 'AddSubscriber' part is the operation name (as defined in the service contract).

Matt





Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Dave Cliffe - MSFT

Hi Matt,

The reason that you are seeing a difference here is that the serializer needs to also support out params. If your operation included out params, your message body would look like this:

<AddSubscriberResponse xmlns="http://tempuri.org">
<AddSubscriberResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Result>
<success>true</success>
</Result>
</AddSubscriberResult>

<param1>45</param1>
</AddSubscriberResponse>

Unfortunately, using MessageContract and isWrapped=false is only way you'd be able to enforce this. Sorry,

-- Dave





Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Matt Dinovo

Without sounding too naive then, is there a way to programmatically import an XSD as MessageContracts Even if I had to programmatically generate a WSDL and then MessageContracts from that, can it be done

Thanks for the help!

Matt





Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Dave Cliffe - MSFT

Hi Matt,

I guess I don't really understand your scenario. Could you explain it for me a little bit Messaging and Data are really two different layers. And, although there needs to be some transformation between the two, the Messaging layer encompasses more than just a collection of DataContracts. It really is tied to the operation itself.

-- Dave





Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Matt Dinovo

Without going into too much detail, the gist of the application I'm writing is for a user to enter an XSD and some operation data (name, the DataContract for the request, and the DataContract for the response) and then, via CodeDOM, a "stub" assembly is created that will simulate the service. As part of the stub, I wanted to write out "canned" XML files representing a response body that a custom endpoint behavior will swap the default respose for. This whole app is driven from the WCF APIs and reflection. I can use the XsdDataContactImporter class to do all of this, but I can't anticipate what the "on-the-wire" message via any API (or at least I can't seem to). I recognize that MessageContracts are the better way to do because of the greater control, but all that I have to work with are XSDs. I suppose I could parse the XSD and build the message contracts up from scratch (via CodeDOM) but with the XsdDataContractImporter available, I'd love to go that route.

I have another workaround I can use to sort of give me what I'm looking for (requires a manual step), but I'd love to be able to do this in an automated way end-to-end.

Matt





Re: Windows Communication Foundation (Indigo) Elements appearing in message body

Dave Cliffe - MSFT

Thanks for the explanation! Given that the operation data you are accepting is just the name and 2 datacontracts, are you restricting your users to only this structure of operation:

Foo OperationName(Bar bar)

Because WCF uses Description for a lot of the internal representation of Contracts and Messages, you may be able to use OperationDescription to fulfill your needs. http://msdn2.microsoft.com/en-us/library/system.servicemodel.description.operationdescription.aspx

Worst case, you can predictably generate these "canned" XML files simply by wrapping your core result with an element named OperationName + "Result". It's a hack, but it would likely fulfill your scenario.

Hope this helps,

-- Dave