none
Migrating wse web services to WCF service RRS feed

  • Question

  • Hi,

    In our project i am migrating the WSE web service to WCF service.

    took help from the blog : http://www.manas.com.ar/waj/2007/05/31/asmx-to-wcf-migration/

    I have created a WCF wrapper by creating ServiceContract interfaces on top of my asmx WEB methods as given in the blog. I have used the XmlSerializerFormat for the new WCF service so that i dont have to make changes to my message contracts. (I dont want to append the MessageContract or DataContract attribute on each request and response as we have hundereds of existing request response messages. It would be very time consuming)

    In the above implementation there is a problem although i am able to hit the new service using the old configuration but request and response schema have changed therefore at the server side i get null in the request using the old configuration. See the schema of the old and new request. There is now and additional wrapped element in the xml in the new schema. I dont know why this is being generated.

    I know that for WebServices we use [SoapDocumentMethod(ParameterStyle = SoapParameterStyle.Bare)] to remove the unnecessay xml wrapping but this is not working in WCF. Any ways to circumvent this in WCF ??

    <soapenv:Header/>
       <soapenv:Body>
          <mes:MyRequest>        
             <mes:Prop1>1254</mes:Prop1>        
          </mes:MyRequest>
       </soapenv:Body>

    However using the new WCF service the request appends a new wrapped xml element in the request as shown below. How do i get rid of this wrapped element. I want this so that our existing clients dont have to change there code when we migrate from asmx to wcf web serivce.

       <soapenv:Header/>
       <soapenv:Body><mem:MyMethod>
             <!--Optional:-->
             <mem:request>
                <!--type: int-->
                <mes:Prop1>3</mes:Prop1>            
             </mem:request>
          </mem:MyMethod></soapenv:Body>

    WCF wrapper

    [ServiceContract(Namespace = "http://abcd.com/xyz")]
        [XmlSerializerFormat]   
        public interface IAServices
        {       
            [OperationContract(Action = "http://abcd.com/xyz/MyMethod", Name = "MyMethod")]
            [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare)]
            MyResponse MyMethod(MyRequest request);
        }

    Actual Service

    public partial class AServices :  IAServices
     {

      [WebMethod(MessageName = "MyMethod")]
      public MyResponse MyMethod(MyRequest request)
      {
       // dosomething
      }

    }

    The request message
     [Serializable]
     [XmlRoot(ElementName = "MyRequest", Namespace = "http://abcd/xyz/Message")]
     public class MyRequest
     {

      public MyRequest()
      {
      }

      [XmlElement(ElementName="Prop1")]
      public int Prop1
      {
       get { return _prop1; }
       set { _prop1 = value; }
      }  
     }

    Can some please help me with this ?

    Monday, December 17, 2012 11:54 AM

Answers

All replies

  • Hi,

    In WCF you can use MessageContract to control the entire SOAP message of operation request/response. (See: Using Message Contracts.) And use the WrappedName, and IsWrapped Property to control how paramaters are formatted.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 19, 2012 6:49 AM
    Moderator
  • Thanks Haixia,

    I tried that also as a last resort and i am facing just one glitch.

    When i specify a MessageContract with the desired namespace on the requrest and response message then also the elements within the MessageContract default to the Service namespace and not the MessageContract Namespace. take for example the code below

    [Serializable]
    [XmlRoot(ElementName = "MyRequest", Namespace = "http://abcd/xyz/Message")]
    [MessageContract(WrapperName= "MyRequest", WrapperNamespace = "http://abcd/xyz/Message")]
     public class MyRequest
     {
      public MyRequest()
      {
      }

      [XmlElement(ElementName="Prop1"),MessageDataMember(Name = "Prop1")]
      public int Prop1
      {
       get { return _prop1; }
       set { _prop1 = value; }
      } 
    }

    This generates the below soap request. The problem is that Prop1 inside the MyRequest defaults to the Service namespace and not the MessageContract Namespace. I know one work around that is by explicitly providing the Namespace for each element inside the MyRequest Message but that is a combursome process. Is there any other short cut way to achieve that ????


    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mes="http://abcd/xyz/Message" xmlns:mem="http://abcd.com/xyz">
       <soapenv:Header/>
       <soapenv:Body>
          <mes:MyRequest>
            
             <mem:Prop1>1234</mem:Prop1> 
          </mes:MyRequest>
       </soapenv:Body>
    </soapenv:Envelope>

    Wednesday, December 19, 2012 9:27 AM
  • Hi,

    Yes, as mentioned in the document, if you do not specify one explicitly, the namespace is the same as the namespace of the service contract that the message is participating in by default.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, December 22, 2012 8:08 AM
    Moderator
  • Is there a way that we can get over this glitch ?? I dont want to make modifications to so many different files. ??

    Thanks in Advance

    Monday, December 24, 2012 6:33 AM
  • I am afraid there is not a better way.

    Best Regards.


    Haixia
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 25, 2012 9:30 AM
    Moderator