0

I have created a WCF webservice using WCF Service Application template in VS 2008. In the same solution i have created a web application project and added the web reference to the service where i gave the service url.

Now when i call the service method from my web application project, i get a timeout, i cannot get the O/P from calling service method. Here's my code i am using to call method from service:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebApplicationClient.WCFService;

namespace WebApplicationClient
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Service1 svc1 = new Service1();
            String ex = svc1.GetData(1,true);


        }
    }
}

EDIT: I have figured out the problem. I added a Web Reference to the service rather than the Service reference and it worked.Can anyone tell me the difference b/w the two?

Also when i run the WCF service , i get this message: Run this command from Command window:

 svcutil.exe http://localhost:1787/Service1.svc?wsdl

But svcutil.exe is not recognised by the OS. I guess it is placed somehwere and i have to give the path also, is this the problem?Where can i find this?

Charu
  • 2,679
  • 6
  • 35
  • 52
  • Are your WCF services started up? – RQDQ Jun 11 '12 at 07:03
  • @RQDQ Yes, i have figured out the problem. I added a Web Reference to the service rather than the Service reference and it worked.Can you tell me the difference b/w the two? – Charu Jun 11 '12 at 07:06
  • 1
    Web reference is the older web service stack (SOAP only I believe). Service reference is the newer WCF stack. However, if you were able to set a web reference, it should have worked fine... – RQDQ Jun 11 '12 at 07:11
  • 1
    Look [here](http://stackoverflow.com/questions/308454/difference-between-web-reference-and-service-reference) for some explanation. – CodeCaster Jun 11 '12 at 07:12
  • @RQDQ No it is not working with WEb Reference.Also i have edited the questions with a few more doubts. – Charu Jun 11 '12 at 07:12
  • @CodeCaster , So does this mean if i add a Service reference i can only communicate within .NET(i.e. the client should also be build using WCF) and i use Add web reference if clients from other platforms would also communicate with my Service. – Charu Jun 11 '12 at 07:14
  • From the link that @CodeCaster gave, there's a statement which says "It is perfectly possible (though not recommended) to add a Web Reference that points to a WCF service, as long as the WCF endpoint uses basicHttpBinding or some compatible custom variant." Now i added the WCF service which by default is using the wsHttpBinding, so i guess i cannot use Add web reference, but why? And if i change it to basicHttpBinding, i just have to modify the web.config, no more changes? – Charu Jun 11 '12 at 07:19

1 Answers1

1

But svcutil.exe is not recognised by the OS. I guess it is placed somehwere and i have to give the path also, is this the problem?Where can i find this?

SvcUtil.exe is the utility that helps to create proxy for a wcf service. You can easily access the utility by opening the Visual Studio command prompt not the windows command prompt.

If you have installed VS in C drive it would be located here.

C:\Program Files\ Microsoft Visual Studio 10.0\VC

This thread talks about the difference between Add Web Reference and Add Service Reference. In your case I would suggest to use Service Reference not Web Reference.

Community
  • 1
  • 1
VJAI
  • 32,167
  • 23
  • 102
  • 164
  • I get an error when i try to run it.Error: Cannot create output file: C:\Program Files\Microsoft Visual Studio 9.0\V C\Service1.cs Access to the path 'C:\Program Files\Microsoft Visual Studio 9.0\VC\Service1 .cs' is denied. I donot have admin rights , is this the problem? Can i change the path where it generates the o/p. – Charu Jun 11 '12 at 09:11
  • 1
    Once you opened the VS command prompt just move to some other drive say D: or E: and then invoke the svcutil.exe. Ex. D:\>svcutil.exe http://localhost:1787/Service1.svc?wsdl – VJAI Jun 11 '12 at 09:25
  • I cannot do CD D:, dont know why, i will try the same at my home machine and see if it works. – Charu Jun 11 '12 at 09:58