Today I exposed my first WCF service in the 'old fashioned' Web Service way. The WCF service behaves exactly as ordinary Web Service hosted in IIS.
It wasn't as easy as I thought. The app.config of the WCF is complicated a bit and I couldn't find appropriate sample. Hmmm, in such case I say: I just don't know what to type in google to find the exact answer. I finally found it here: http://msdn2.microsoft.com/en-us/library/ms731134.aspx. The article describes how to create WCF service that can be used with ordinary Web Service client. Let me put my own sample here:
The WCF service exposed as ordinary Web Service:
[ServiceContract]
public interface IMyService
{
[OperationContract]
long DoSomething(string parameter);
}
public class MyService : IMyService
{
public long DoSomething(string parameter)
{
return -1;
}
}
Here goes the app.config file that configures the service:
<!-- WCF configuration. -->
<system.serviceModel>
<services>
<service name="MyService"
behaviorConfiguration="HttpGetMetadata">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8090/MyService" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="IMyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="HttpGetMetadata">
<!-- To enable WSDL retrieval set the httpGetEnabled to true. -->
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
As you can see: the configuration is not so simple and without an exact sample I made many mistakes even though I knew how to configure it.
OK. It works this way.
Then I run my server application hosting the MyService and I could add a 'Web Reference' in Visual Studio using address of the MyService suffixed with '?wsdl'. It works great. I was thrilled as I created a Web Service without using IIS - something I always dream about (Only WSE and WCF can do such a thing). Everything works fine and my Web Service client speaks to the WCF Web Service. Now I can develop logic of the Web Service.