|
Recently I was tasked to help devise a plan to refactor an application that was exposing non-compliant SOAP web services. I took a closer look at the application and decided that the best route would be to use the WCF to implement the refactored services. The old service had published XSDs for request and response of the web services. It was necessary to keep backward compatibility and keep these same XSDs valid for the new services. With that in mind I devised the following plan
1. Convert the schemas to CS classes using the XSD tool
2. Create a new WCF Service Application
3. On project click add existing items and add the two generated classes
4. Rename the IService1.cs file to I[yourserviceName]Service.cs
5. Change the Interface as follows
a. [ServiceContract(Namespace="your namespace")]
b. [XmlSerializerFormat(Style=OperationFormatStyle.Document,Use=OperationFormatUse.Literal)]
6. Include a template for serializing and de-serializing classes (ObjectXMLSerializer.cs fond in downloads) in your project
7. Rename the interface and change the method inside to have the form
a. [OperationContract(Name = "Name", Action = "URL")]
b. Response Service(Request req);
8. Rename Service1.svc to Yourservicename.svc
9. Open the code behind
10. Rename the class and the inheriting interface
11. Implement the method to be in form
[ServiceBehavior(Namespace=”Your Name space ",IncludeExceptionDetailInFaults=true)]
public class YourService : IYourService
{
public YourServiceResponse Service(YourServiceRequest req)
12. Update the config.web file
<servicename="YourServiceNameSpace.YourService"behaviorConfiguration="YourServiceNamespace.YOurService1Behavior">
<!-- Service Endpoints -->
<endpointaddress=""binding="wsHttpBinding"contract="YourServiceNameSpace.IYourService">
13. Update the .svc file directive <%@ ServiceHost Language="C#" Debug="true" Service="YoursServiceNameSpace.YourService" CodeBehind="YourServiceService.svc.cs" %>
14. Set .svc as the starting page press and the project as the starting project
15. Now is the tricky part we add a Message wrapper class on the generated schema to control the message serialization, so Open the CS Request Schema
a. ADD code similar to the following
using System.ServiceModel;
[MessageContract(IsWrapped = false)]
public class YourServiceRequest
{
[MessageBodyMember(Name = "REQUEST", Namespace = "YourNameSpace")]
public Request request;
}
b. ADD code similar to the following
using System.ServiceModel;
[MessageContract(IsWrapped = false)]
public class YourServicesResponse
{
[MessageBodyMember(Name="RESPONSE")]
public Response response;
}
Press f5 you should see the service description press on WSDL and you will see the WSDL
Hope this helps:)
|