none
How to change the namespace when using message contracts? WrapperNamespace isn't working. RRS feed

  • Question

  • Hi guys,

    I know this isn't the right forum for my question. But the WCF forum seems to be kinda "inactive". I posted my question there, but I got no response. Please don't ask me to move my question. Just help me! Please!

    I'm trying to develop an ASP.NET application that consumes a WCF service running on a remote computer. I added a service reference into my project using Visual Studio's Add Service Reference tool. Now I have a problem using one of the operations.

    The Add Service Reference tool created a proxy for me. The code that it generated looks like this (This is not the actual code. I cannot post the actual code for security reasons. However, this is a copy of the code):

    System.ServiceModel.ServiceContractAttribute([Namespace]:="http://example.com/Vendors", ConfigurationName:="VendorServiceConfig")> _
    Public Interface IVendorService
    
         <System.ServiceModel.OperationContractAttribute(Action:="http://example.com/Vendors#get_vendor_info", ReplyAction:="*"), _
         System.ServiceModel.XmlSerializerFormatAttribute(Style:=System.ServiceModel.OperationFormatStyle.Document, SupportFaults:=True, Use:=System.ServiceModel.OperationFormatUse.Literal)>
         Function get_vendor_info(ByVal request As PB.VendorAdminService.get_vendor_info_request) As PB.VendorAdminService.get_vendor_info_response
    
    End Interface
    
    Public Class VendorService
         Implements IVendorService
    
         Function get_vendor_info(ByVal request As PB.VendorAdminService.get_vendor_info_request) As PB.VendorAdminService.get_vendor_info_response Implements IVendorService.get_vendor_info
    
             'Some code here
    
         End Function
    End Class
    
    
    <System.ServiceModel.MessageContractAttribute(WrapperName:="get_vendor_info", WrapperNamespace:="http://example.com/Vendors", IsWrapped:=True)> _
    Partial Public Class get_vendor_info_request
    
            <System.ServiceModel.MessageBodyMember([Namespace]:="", Order:=0)> _
            Public VendorID As String
    
    End Class
    
     <System.ServiceModel.MessageContractAttribute(WrapperName:="get_vendor_info_response", WrapperNamespace:="http://example.com/Vendors", IsWrapped:=True)> _
    Partial Public Class get_vendor_info_response
    
         <System.ServiceModel.MessageBodyMember([Namespace]:="", Order:=0)> _
            Public VendorName As String
    
         <System.ServiceModel.MessageBodyMember([Namespace]:="", Order:=1)> _
            Public VendorAdddress As String
    
    End Class

    I have added an IClientMessageInspector instance to the Behaviors property of the client proxy. This class is used to inspect the SOAP messages, and modify them.

    Now, my problem is, the returned SOAP messages are not being de-serialized properly. No exceptions are thrown, but also no data is returned. But if I use the inspector, I can see that the SOAP messages are well-formatted, and they're making their way to the service, and back. The problem is with de-serializing the data.

    So, I tried to force the de-serialization to use my class. I used the IClientMessageInspector.AfterRecieveReply method. One of the params passed to this method has a type of System.ServiceModel.Channels.Message. This type has a method called GetBody(Of T). It's suppose to de-serialize the SOAP messages using the type that you passed. I used this method like this:

    Dim response = message.GetBody(Of PB.VendorAdminService.get_vendor_info_response)()

    Now, I'm receiving this error: Error in line 1 position 766. Expecting element 'get_vendor_info_response' from namespace 'http://schemas.datacontract.org/2004/07/Project_Name.PB.VendorAdminService'.. Encountered 'Element'  with name 'get_vendor_info_response', namespace 'http://example.com/Vendors'.

    I never specified that 'schemas.datacontract' namespace. I wonder where did it get it from. I tried to explicitly specify the namespace in the WrapperNamespace property, but nothing. In fact it throws the same error no matter what I change the WrapperNamespace property to.

    Now my question is: How can I change the namespace of my response class to what the de-serializer is expecting?

    Please help!

    Abdul

    Tuesday, August 27, 2013 5:02 PM

Answers