Web.config made automatically according to WCF service

panJames
panJames used Ask the Experts™
on
Hello experts!

I am trying to get my head around example I found on internet.

I am trying to re- create the example of simple service I found on internet.

This is what I do:

1. VS2005 Pro -> new project -> class library

2. I have three files my service consists from:


A.

*** DataContract.cs***


using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace SampleService
{
    [DataContract]
    public class Request
    {
        string name;

        [DataMember]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

    [DataContract]
    public class Response
    {
        string message;

        [DataMember]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }
    }

}


B.

***Service.cs***

using System;
using System.Collections.Generic;
using System.ServiceModel;

namespace SampleService
{
    [ServiceBehavior]
    public class Service: ISampleService
    {
        [OperationBehavior]
        public Response GetMessage
            (
            Request request
            )
        {

            Response response = new Response();

            if ( null == request )
            {
                response.Message = "Error!";
            }
            else
            {
                //set the message
                response.Message = "Hello, " + request.Name;
            }

            return response;
        }

        [OperationBehavior]
        public string SayHello()
        {
            return "Hello, World!";
        }
    }
}

C.

***ServiceContract.cs***

using System;
using System.ServiceModel;

namespace SampleService
{
    [ServiceContract]
    public interface ISampleService
    {
        [OperationContract]
        Response GetMessage
            (
            Request request
            );

        [OperationContract]
        string SayHello();
    }
}

I understand that I need service.svc file, so I have it:

***Service.svc***

<% @ServiceHost
            Language=C#
            Service="SampleService.Service"
%>



Questions:


1. How can I configure VS to create Web.Config file automatically when I build my service and put it into selected folder?

Thank you

panJames




Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
And also how to configure VS to make it copy built service.dll into two different folders automatically?

Thank you

panJames
I am not sue how you can do it in VS 2005 however in 2008 simply :New Project=>Visual C#=>Web=>WCF Service Application
This will automatically create all the necessary files including web.config .
To copy the dll:
Project->Properties->Build Events->Post-build command line , Add something like:
copy $(TargetPath) "C:\Some folder to copy to\" /y

Author

Commented:
SunnyDark:

tried:

copy $(TargetPath) "C:\Some folder to copy to\" /y
copy $(TargetPath) "C:\Some folder to copy to\"

It says: system didn't find the file specified.

Which is weird because paths I can see in the output message are correct.

******************************
Tried such a thing:

copy "I typed the same path I could read from output message" "C:\Some folder to copy to\"

it works fine!

Any idea what is going on?

Thank you

panJames

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial