To show my problem I created a simple WCF service with operations that use a message class with [MessageContract]
attribute. This message contains the MyHeader
property and is annotated with the [MessageHeader]
attribute.
[MessageContract] public class HeaderedMessage
{
[MessageHeader] public string MyHeader { get; set; }
}
[ServiceContract] public interface IService
{
[OperationContract] void GetDataUsingDataContract(HeaderedMessage headered);
}
public class Service : IService
{
public void GetDataUsingDataContract(HeaderedMessage headered) { }
}
Then I tried to generate the proxy classes for Silverlight 4 (or 5) using SlSvcUtil.exe
:
slsvcutil.exe http://localhost:8732/Design_Time_Addresses/MessageHeaderedService/?wsdl
Without any warning the message headers are totally ignored in the generated classes. Hence the HeaderedMessage
does not contain any property at all.
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.MessageContractAttribute(WrapperName="HeaderedMessage", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class HeaderedMessage
{
public HeaderedMessage()
{
}
}
I did not find any information at MSDN or through Google search about this weired behaviour. Has anybody else issues with this?
I also tried to use Portable Class Libraries extension to use the IService
contract directly through ChannelFactory
within the Silverlight application. As the System.ServiceModel
assemblies of Silverlight don't contain the MessageHeaderAttribute
class it cannot be compiled.
Update: Missing generated WSDL and the WCF System.ServiceModel
section:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="Service" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:8732/Design_Time_Addresses/MessageHeaderedService/?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:8732/Design_Time_Addresses/MessageHeaderedService/?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="HeaderedMessage">
<wsdl:part name="parameters" element="tns:HeaderedMessage"/>
</wsdl:message>
<wsdl:message name="HeaderedMessage_Headers">
<wsdl:part name="MyHeader" element="tns:MyHeader"/>
</wsdl:message>
<wsdl:message name="IService_GetDataUsingDataContract_OutputMessage"/>
<wsdl:portType name="IService">
<wsdl:operation name="GetDataUsingDataContract">
<wsdl:input wsaw:Action="http://tempuri.org/IService/GetDataUsingDataContract" name="HeaderedMessage" message="tns:HeaderedMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService/GetDataUsingDataContractResponse" message="tns:IService_GetDataUsingDataContract_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IService" type="tns:IService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetDataUsingDataContract">
<soap:operation soapAction="http://tempuri.org/IService/GetDataUsingDataContract" style="document"/>
<wsdl:input name="HeaderedMessage">
<soap:header message="tns:HeaderedMessage_Headers" part="MyHeader" use="literal"/>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service">
<wsdl:port name="BasicHttpBinding_IService" binding="tns:BasicHttpBinding_IService">
<soap:address location="http://localhost:8732/Design_Time_Addresses/MessageHeaderedService/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
The WCF config:
<system.serviceModel>
<services>
<service name="MessageHeaderedService.Service">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/Design_Time_Addresses/MessageHeaderedService/" />
</baseAddresses>
</host>
<endpoint address ="" binding="basicHttpBinding" contract="MessageHeaderedService.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>