Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hai to all,

I am new to WCF.I don't knew the idea on how to create a client class.I implement some method in service1.cs.Then afterwards i put this command in command prompt "svcutil.exe http://localhost:53391/Service.svc?wsdl".But the error is coming.Plz tell me the concept oto create client class

Iservice1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService3
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string GetData(string value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}
service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService3
{
    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}
Posted
Updated 20-Feb-11 19:17pm
v2
Comments
Sergey Alexandrovich Kryukov 21-Feb-11 0:58am    
How you can hope for any answer?! Where is you error, where is your code?
--SA
sridharan28 21-Feb-11 1:13am    
it showing error"directory listing/--"

1 solution

You'll need to make sure the service is running when attempting to execute the proxy generation.
Judging by the URL http://localhost:53391/Service.svc?wsdl you are generating against the build server. If so make sure Cassini (the lightweight web server bundled with VS) is running, you can check this by opening the URL in a web browser: you should get the wsdl file.

You can directly reference the Service in the client code if it is part of the same solution, in this case the proxies are generated for you, and they keep up to date with service changes.

If none of this helps, can you give use the error message.
 
Share this answer
 
Comments
sridharan28 21-Feb-11 6:47am    
After i write the url in command prompt i got the error.my url is"http://localhost:3541/WCFService1/Service.svc?wsdl".It shows the error message "svcutil is not recognised".Can i use svcutil in the url?
Keith Barrow 21-Feb-11 6:54am    
You need to either give the path of svcutil (it comes with the framework) or use the CD command to move to it's directory before executing. Another option is to start the visual studio command prompt
Start-> Programs->Microsoft Visual Studio 2008-> Visual Studio Tools->Visual Studio 2008 Command Prompt

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900