Geeks With Blogs
Marcin Celej blog

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.

Posted on Thursday, September 27, 2007 9:18 AM | Back to top


Comments on this post: Exposing Web Service from your app using WCF

# re: Exposing Web Service from your app using WCF
Requesting Gravatar...
I would like to knw the details of hosting the same app in IIS, So that I will be able to call the function DOSOmething() somewhere in the application;
Left by Neal gabriel on Jul 22, 2008 9:24 PM

# re: Exposing Web Service from your app using WCF
Requesting Gravatar...
Hi...
This document is dated September 2007. I am interested in knowing what is the current status of WCF web services. is it just used as an end point to asmx web services? or it is used independent of them also? it was introduced in .net 3.0 .. so are there any changes made in .net 3.5? i am beginner in .net.

by reading the wsdl of asmx service i can create a proxy class and interact with the service. how this can be done in case of wcf? are there any standard methods which can be used?
the same method can be applicable to wcf web services also?

i want to learn more on this.
Left by Mrunal on Feb 26, 2009 6:11 AM

Your comment:
 (will show your gravatar)


Copyright © Marcin Celej | Powered by: GeeksWithBlogs.net