简体   繁体   中英

Backwards and forwards compatibility from an upgraded web service from ASMX to WCF

Recently I've upgraded my ASMX web service, that exposes two operations, to WCF, to work with different consumers. With this upgrade, WSDL SOAP Action changed from <namespace>/<operation> to <namespace>/<service>/<operation> . Problem is, I need to still be able to have my service used by previous consumers and they only have my previous WSDL definition. When they send a request, they get a HTTP 500 error.

What I've tried:

  1. Force my OperationContract method to responde to Action="*" and this worked fine until I did the same to the other operation. I've learned that I can't have multiple OperationContract methods to responde to any soap action.
  2. Use some kind of handler to catch the ProtocolException like IHttpModule or IErrorHandler and redirect the request to the desired operation. I've registered my IHttpModule class with success but I can't get any valid information from my request in any EventHandler . IErrorHandler doesn't even work.

Is there any way that I can accomplish this?

My service class:

namespace sappi
{
    [ServiceContract(Namespace = "sappi")]
    [XmlSerializerFormat]
    public interface IService
    {
        //[OperationContract]
        [OperationContract(Action = "*", ReplyAction = "*")]
        int put(Service.PutRequest putRequest);

        [OperationContract]
        int confirm(Service.ConfirmRequest confirmRequest);
    }

My IHttpModule class:

namespace sappi
{
    public class Handler : IHttpModule
    {

        public void Init(HttpApplication application)
        {
            application.BeginRequest += new EventHandler(beginRequest);
            application.EndRequest += new EventHandler(endRequest);
        }

        private void beginRequest(Object source, EventArgs e)
        {
            //Log stuff...
        }

        private void endRequest(Object source, EventArgs e)
        {
            //Log stuff...
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }

Thank you in advance.

Backwards and forwards compatibility from an upgraded web service from ASMX to WCF

Though you possibly could fuse both ASMX and SOAP services into one system, it would be rather tricky as they both would fight over HTTP ownership.

Instead you probably would be better off maintaining your original ASMX service and create a new SOAP service.

This allows for two endpoints:

  1. your original ASMX HTTP endpoint
  2. a new SOAP endpoint in whatever protocol. It could be HTTP:8080; TCP; or pipes (though probably not the latter for the Internet)

Common Business Logic

Next you need to refactor your original service so that all business logic is in a new common service-agnostic library that both your ASMX and SOAP service can use.

Once done, there should be minimal code in both services proper whilst allowing for backward compatibility via the ASMX endpoint and future expansion in the SOAP endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM