tags:

views:

54

answers:

2

I am not sure if this is the correct way of doing but I read that you not suppose to have a WCF Service Library reference in your web form project rather you add endpoints to your web.config, is that true?

Here is what I have done:

  1. create a WCF service library project
  2. create a simple service called "MyService.svc"

WebForm:

  1. Create a web project
  2. create a WCF Service and in it i have this code

    <%@ ServiceHost Language="C#"
        Service="WCFJQuery.ContactBLL.Implementation.ContactUs"
        Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
    
  3. right click on the web proejct and "Add Reference" and add teh MyService.dll reference from WCF service library project.

Is this something how you suppose to do?

+1  A: 

If you control both ends of the communication (both the server side and the client), and both are .NET, you have two options:

  1. either add your service references like you normally would (if you don't control both sides) - in that case, you get a client-side proxy class, which implements the proxy for the service methods, and all the data contracts are duplicated (you get classes in your client proxy namespace, that will serialize to and deserialize from the same XML representation in the message that is sent back and forth - but the classes are different, since they live in a different namespaces)

or, optionally:

  1. you can put all your service contracts, data contracts and so on into a separate "MyService.Contracts" assembly (call it whatever makes sense to you), and then you can share that assembly; on the server-side, your code that implements the service contract will have a reference to that shared assembly - and on the client side, you do the same thing, basically: your client project will add a reference to that shared assembly, and now you have all your data contracts (your "message" types) only once - in the shared assembly namespace.

Option #2 does have its clear advantages, but again:

  • it only works if you control both sides of the communication
  • it only works if both sides are .NET code
  • since you don't use the built-in Add Service Reference mechanism, you might need to manually create some of your client-side configuration (it's really not that hard)

I hope this gives you a few ideas and insights - if you have further concrete questions - you know where to ask!

marc_s
@Marc_s: thanks for the reply, currently my setup is both (client/server) in .net so i am adding my assembly reference in my web site project and working great but just wanted to make sure i am following the right pattern.
Abu Hamzah
+1  A: 

You may be hearing about how to use WCF in a Web Site "project". The better solution, in my opinion, is to use a Web Application Project instead, using File->New Project. Web Site "projects" behave strangely, and unlike every other project type in Visual Studio.

John Saunders
+1 - yes definitely - use Web **Application** projects - much better and much more control.
marc_s
like what did you find strange, just curious to know.
Abu Hamzah
Like they build at runtime, rather than at compile time. Like there is no project file. Like every way they're different from every other kind of project in Visual Studio. The difference should have been a hint to Microsoft, but they didn't get the hint.
John Saunders