Reputation: 3667
I have a VS2012 solution with an app.config. I have multiple projects in the solution. Lets define it like so:
Root.csproj >> the startup project
->Orders.csproj
->Customers.csproj
->Purchasing.csproj
Now, when I add a service reference to the Orders project it sticks the binding and endpoint information into the app.config in the Orders.csproj. However, when I run the application I get the expected exception:
Exception: Could not find default endpoint element that references contract 'OrderService.IOrderService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
This is because the app.config in Root does not contain the binding/endpoint configuration. I can easily copy the bindings and endpoints from orders\app.config to the root\app.config and execute the service methods successfully. My question is why must I do this? Is there a way to tell the root\app.config to gather other endpoints from the orders\app.config? It seems silly that adding the service reference doesn't automatically add the binding and endpoints to the root\app.config if it is required for the service methods to execute successfully. Any suggestions are much appreciated. Thanks.
Upvotes: 0
Views: 976
Reputation: 27904
There are server side "endpoints".........
But on the client........you have to add some entries that point to the server side endpoints.
To answer your question, (no), you MUST define information on the client side. It is basically saying "here is where to find the service you want to use"
They will look very similar.
SERVER SIDE:
<endpoint
address = "http://localhost:8001/MammalControllerFascade"
binding = "wsHttpBinding" bindingConfiguration="WSHttpBindingName1"
contract = "GranadaCoder.Applications.TrinugWCFDemoVersion1.Interfaces.Controllers.IMammalController" >
</endpoint>
<endpoint
address = "net.pipe://localhost/LocalMammalControllerFascade"
binding = "netNamedPipeBinding" bindingConfiguration="NamedPipeBindingName1"
contract = "GranadaCoder.Applications.TrinugWCFDemoVersion1.Interfaces.Controllers.IMammalController" >
</endpoint>
CLIENTSIDE
<client>
<endpoint name="WSHttpEndPoint"
address = "http://localhost:8001/MammalControllerFascade"
binding = "wsHttpBinding" bindingConfiguration="WSHttpBindingName1"
contract = "GranadaCoder.Applications.TrinugWCFDemoVersion1.Interfaces.Controllers.IMammalController" >
</endpoint >
<endpoint name="NamedPipeEndPoint"
address = "net.pipe://localhost/LocalMammalControllerFascade"
binding = "netNamedPipeBinding" bindingConfiguration="NamedPipedBindingName1"
contract = "GranadaCoder.Applications.TrinugWCFDemoVersion1.Interfaces.Controllers.IMammalController" >
</endpoint >
</client>
Note, they are similar. Note, on the client side, the ENDPOINT has a name. That is so the client can refer to the ENDPOINT by name.
EDIT:
Are you running both the Host and the Client?
You cannot just run the client in debug mode. The service must be started.
Right click the solution, properties..............and set up 2 start up projects. (if you are self-hosting)
If you are not self-hosting.....then how are you "serving up server" ? (what is running the server side code) during debug?
EDIT:
I store my "sectional information" in different files. So I can maintain them without getting everything garbled up in the same app.config (or web.config).
Here is a sample:
APP.CONFIG (or web.config)
<system.serviceModel>
<behaviors configSource="WCFBehaviors.config">
</behaviors>
<bindings configSource="WCFBindings.config">
</bindings>
<client configSource="WCFClient.config">
</client>
<services configSource="WCFServices.config">
</services>
</system.serviceModel>
and I'll show one of the files above.
contents of "WCFClient.config" seen below. The other files follow the same pattern.
<client>
<endpoint name="WSHttpEndPoint"
address = "http://localhost:8001/MammalControllerFascade"
binding = "wsHttpBinding" bindingConfiguration="WSHttpBindingName1"
contract = "GranadaCoder.Applications.TrinugWCFDemoVersion1.Interfaces.Controllers.IMammalController" >
</endpoint >
<endpoint name="NamedPipeEndPoint"
address = "net.pipe://localhost/LocalMammalControllerFascade"
binding = "netNamedPipeBinding" bindingConfiguration="NamedPipedBindingName1"
contract = "GranadaCoder.Applications.TrinugWCFDemoVersion1.Interfaces.Controllers.IMammalController" >
</endpoint >
</client>
Upvotes: 1