locked
Converting ASMX contracts to WCF RRS feed

  • Question

  • I have an older webservice I need to convert into a new system which isn't hosted in IIS, so I can't copy it directly. I can create self hosted WCF services so I could put the functionality there instead. However, I can't get the contracts to match up as the client we already have gives the following exception when connecting to the webservice:

    The message with action 'http://services.mysite.com/MyService/MyMethod' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher.

    I read in some other SO posts that I could ensure the contract would be the same by running the following in a command prompt:

    wsdl.exe /serverInterface http://oldservices.mysite.com/MyService.asmx?WSDL

    This command generates some code which, according to the documentation (https://msdn.microsoft.com/en-us/library/vstudio/7h3ystb6(v=vs.100).aspx), "Generates interfaces for server implementation".

    I took this code into my new solution and got it to start (after adding some extra attributes, and also prettifying the code), and I can call MyMethod successfully from WebService Studio (https://webservicestudio.codeplex.com/) and get the expected results. However, the old client still complains with the same exception.

    What must I do to successfully convert an old ASMX webservice into a fully compatible WCF service?

    WSDL of old ASMX webservice: http://pastebin.com/cLmQHeVa

    Generated Server Interface (from wsdl.exe): http://pastebin.com/QbhKGjYG

    My adjusted interface

    [WebServiceBinding(Name = "MyServiceSoap", Namespace = "http://services.mysite.com/MyService")]
    [XmlInclude(typeof(Foo))]
    [XmlInclude(typeof(Bar))]
    [ServiceContract]
    [ServiceKnownType(typeof(Foo))]
    [ServiceKnownType(typeof(Bar))]
    public interface IMyServiceSoap {
    
        [OperationContract, XmlSerializerFormat(Style = OperationFormatStyle.Document)]
        [WebMethod]
        [SoapDocumentMethod("http://services.mysite.com/MyService/MyMethod", RequestNamespace = "http://services.mysite.com/MyService", ResponseNamespace = "http://services.mysite.com/MyService", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    
        ReturnMessage MyMethod();
    }

    My adjusted type definitions

    [Serializable]
    [XmlType(Namespace = "http://services.mysite.com/MyService")]
    public class ReturnMessage {
        public ReturnStatus Status { get; set; }
        public object GenericReturn { get; set; }
    }
    
    [Serializable]
    [XmlType(Namespace = "http://services.mysite.com/MyService")]
    public enum ReturnStatus {
    }
    
    [Serializable]
    [XmlType(Namespace = "http://services.mysite.com/MyService")]
    public class Foo {
        public string Text { get; set; }
    }
    
    [Serializable]
    [XmlType(Namespace = "http://services.mysite.com/MyService")]
    public class Bar {
        public int Number{ get; set; }
    }

    Implementation class

    public class MyServiceSoap : IMyServiceSoap {
        public ReturnMessage MyMethod() {
            return new ReturnMessage() { Status = ReturnStatus.OK, GenericReturn = new Foo() };
        }
    }

    WCF starter

    ServiceHost host = new ServiceHost(typeof(MyServiceSoap), new Uri("http://locahost:8080/MyService.asmx"));
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy12;
    host.Description.Behaviors.Add(smb);
    host.Open();


    Friday, July 3, 2015 7:04 AM

Answers

  • Hello Vensafe,

    >>What must I do to successfully convert an old ASMX webservice into a fully compatible WCF service?

    For such an issue, since we do not know how you write the webservice and the client, what we can do is to provide some related information:

    How to: Migrate ASP.NET Web Service Code to the Windows Communication Foundation

    Migrating ASMX Services to WCF Services

    Please check if they are helpful. By the way, since you are trying to convert a web service to the WCF, you may get help on the WCF forum since the current one is specifically for WCF Data Services which is a bit different from WCF.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Vensafe AS Monday, July 6, 2015 2:02 PM
    Monday, July 6, 2015 2:28 AM
    Moderator

All replies

  • Hello Vensafe,

    >>What must I do to successfully convert an old ASMX webservice into a fully compatible WCF service?

    For such an issue, since we do not know how you write the webservice and the client, what we can do is to provide some related information:

    How to: Migrate ASP.NET Web Service Code to the Windows Communication Foundation

    Migrating ASMX Services to WCF Services

    Please check if they are helpful. By the way, since you are trying to convert a web service to the WCF, you may get help on the WCF forum since the current one is specifically for WCF Data Services which is a bit different from WCF.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Vensafe AS Monday, July 6, 2015 2:02 PM
    Monday, July 6, 2015 2:28 AM
    Moderator
  • I had already previously read the "Migrating ASMX Services to WCF Services" without any success.

    The "How to: Migrate ASP.NET Web Service Code to the Windows Communication Foundation", however, was new to me and proved to be very fruitful.

    The code is not as clean as I had hoped it would be, but our old client can now communicate with the new WCF webservice just fine without any contract mismatch errors.

    Thanks for the point in the right direction :)

    Monday, July 6, 2015 2:02 PM