Step 1: Create an empty Web Application
Step 2: Add new Web Service in this project
Now we can see the dummy code that is generated by Web Service default Template.
Here we have a WebService class inherited from System.Web.Services.WebService. Class also have a web method “HelloWorld” that returns “Hello World” string.
Step 3: Add reference of System.ServiceModel in your project.
Step 4: Add “ServiceContract” and “OperationContract” on class and method, and add
using System.ServiceModel; on the top of the code
Step 5: Add WCFService in same project.
Step 6: Remove WCF Service interface “IWCFService” and Class “WCFService.svc.cs” files.
Step 7: Right click on .svc and .asmx file and Go to view Markup.
.svc markup view:
< %@ ServiceHost Language="C#" Debug="true" Service="ConvertWebServiceToWCFService.WCFService" CodeBehind="WCFService.svc.cs" %>
.asmx markup view:
< %@ WebService Language="C#" CodeBehind="WebService.asmx.cs" Class="ConvertWebServiceToWCFService.WebService" %>
Step 8: Change .svc and .asmx markup as below
.svc markup view:
< %@ ServiceHost Language="C#" Service="ConvertWebServiceToWCFService.WCFService" %>
.asmx markup view:
< %@ ServiceHost Language="C#" Service="ConvertWebServiceToWCFService.WebService" %>
Step 9: Changes in Web.Config file. Open config file.
Add below settings under
< compilation debug="true" targetFramework="4.0">
< buildProviders>
< remove extension=".asmx"/>
< add extension=".asmx" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
< /buildProviders>
< /compilation>
< httpHandlers>
< remove path=".asmx" verb="*" />
< add path="*.asmx" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" validate="false" />
< /httpHandlers>
Add this also in web.config file of service.
< system.serviceModel>
< services>
< service name="MyService" behaviorConfiguration="MyServiceTypeBehaviors">
< endpoint contract="ConvertWebServiceToWCFService.WebService" binding="mexHttpBinding" address="mex" />
< /service>
< /services>
< behaviors>
< serviceBehaviors>
< behavior name="MyServiceTypeBehaviors">
< serviceMetadata httpGetEnabled="true" />
< serviceDebug includeExceptionDetailInFaults="true" />
< /behavior>
< behavior name="">
< serviceMetadata httpGetEnabled="true" />
< serviceDebug includeExceptionDetailInFaults="false" />
< /behavior>
< /serviceBehaviors>
< /behaviors>
< serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
< /system.serviceModel>
Step 10: Finally you can see Conversion is working fine:
No comments:
Post a Comment