more than one endpoint configuration for that contract was found - wcf

I have a question about my soap services(wcf)
I implement my wcf service and all the function implement correctly at compile time
I do not have any compile time error but when i run my code I received this error message
An endpoint configuration section for contract 'test.ICore' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration
I think in soap services we need some change in web.config file
another point is that my project have multiple soap services.
may it cause a problem?
how can i solve this issue?
thank you so much

I think your problem is because of you have a multiple endpoint with the same address in your web.config file
like that
<binding name="TestSoap">
<security mode="Transport" />
</binding>
<binding name="TestSoap" />
<endpoint address="http://TestSoap/Core.svc/soap"
binding="basicHttpBinding" bindingConfiguration="Soap" contract="TestSoap.ICore"
name="TestSoap" />
<endpoint address="https://TestSoap/Core.svc/soap"
binding="basicHttpBinding" bindingConfiguration="TestSoap"
contract="TestSoap.ICore" name="TestSoap" />
you can use this example for your code.
I hople you can solve your problem

In general, an interface contract can be supported by multiple endpoints, but bindings and addresses can vary, such as this:
Server-side:
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<endpoint address="secure"
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</service>
Client-side:
<client>
<endpoint name="basic"
address="http://localhost/servicemodelsamples/service.svc"
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<endpoint name="secure"
address="http://localhost/servicemodelsamples/service.svc/secure"
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</client>
In the call:
CalculatorClient client = new CalculatorClient("basic");
Console.WriteLine("Communicate with basic endpoint.");
client = new CalculatorClient("secure");
Console.WriteLine("Communicate with secure endpoint.");
Feel free to contact me if have any issues.

Related

Muliple Service Behaviors to same service in WCF

Can we attach multiple service behaviors to the same service in WCF.If yes how can we do that - via config file or as attributes?
Yes, you can.
ServiceEndpoint has a Behaviors collection.
So if you create a service in C# code, you may add any behavior to this collection: standard or your one. The example of how to create custom behavior and add it to the endpoint see here. Keep in mind that you can create and add as many behaviors as you need.
If you want to add behaviors in the configuration, you will need to create Behavior configuration extension. Here is an example hot to create it and add it to the endpoint in config file.
EDIT:
Service behaviors can be added in absolute same way
Yes you can.
You need to configure your behaviors and, in service tag, configure each behavior, like this:
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- First behavior:
http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- Second behavior, with secure endpoint exposed at {base address}/secure:
http://localhost/servicemodelsamples/service.svc/secure -->
<endpoint address="secure"
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
</service>
The same service for ICalcular, for two different behaviors.
Read more here: https://msdn.microsoft.com/en-us/library/ms751515.aspx
Yes We can Create Multiple end points
<services>
<service name="ReportService.ReportService">
<endpoint
address="ReportService"
binding="netTcpBinding"
contract="ReportService.IReportService">
</endpoint>
<endpoint
address="ReportService"
binding="basicHttpBinding"
contract="ReportService.IReportService">
</endpoint>
</service>
</services>
we can create multiple end points like this.in client side app.config or webconfig file it show like this
<bindings>
<netTcpBinding>
<binding name="netTcpBinding_IReportService" />
</netTcpBinding>
<basicHttpBinding>
<binding name="basicHttpBinding_IReportService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="" binding="netTcpBinding"
bindingConfiguration="netTcpBinding_IReportService" contract="ServiceReference.IReportService"
name="netTcpBinding_IReportService">
</endpoint>
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding_IReportService" contract="ServiceReference.IReportService"
name="basicHttpBinding_IReportService">
</endpoint>
</client>
Then we should mention the binding name while we are referring
ServiceReference.ReportServiceClient client = new ServiceReference.ReportServiceClient(netTcpBinding_IReportService);
Now it will work with netTcpBinding

Is there a way to call 'Update Service Reference' without it changing the App.Config?

Ok, I manage my own App.Config. I don't need a wizard to do it for me, thank you very much. And the code that it puts in my App.Config is verbose garbage. I am capable of writing my own WCF endpoints and bindings. I just want Visual Studio 2010 to do what it is best at doing: code generation. Just give me the server and data-contract code! Is there any way to turn this off? Is there a way to call 'Update Service Reference' without VS changing the App.Config? Its very frustrating. Now it gives me an exception unless I completely delete all of the endpoint nodes from my App.Config.
This is the exception that I get:
There was an error downloading
'http://localhost:8732/MyService/mex'.
The request failed with HTTP status 400: Bad Request.
A child element named 'endpoint' with same key already exists at the
same configuration scope. Collection elements must be unique within
the same configuration scope (e.g. the same application.config file).
Duplicate key value:
'contractType:Web.DataService.MyService.IMyService;name:MyService.Live'.
(C:\ProjectPath\App.config line 152)
And here is my App.Config:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Binding.Debug" maxReceivedMessageSize="2147483647">
</binding>
<binding name="Binding.Secure" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<!-- Debug client endpoints -->
<endpoint name="MyService.Debug"
contract="Web.DataService.MyService.IMyService"
address="http://localhost:8732/MyService"
binding="wsHttpBinding"
bindingConfiguration="Binding.Debug"
/>
<endpoint name="MyService1.Debug"
contract="Web.DataService.MyService1.IMyService1"
address="http://localhost:8732/MyService1"
binding="wsHttpBinding"
bindingConfiguration="Binding.Debug"
/>
<endpoint name="MyService2.Debug"
contract="Web.DataService.MyService2.IMyService2"
address="http://localhost:8732/MyService2"
binding="wsHttpBinding"
bindingConfiguration="Binding.Debug"
/>
<endpoint name="MyService3.Debug"
contract="Web.DataService.MyService3.IMyService3"
address="http://localhost:8732/MyService3"
binding="wsHttpBinding"
bindingConfiguration="Binding.Debug"
/>
<!-- Local client endpoints -->
<endpoint name="MyService.Local"
contract="Web.DataService.MyService.IMyService"
address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService1.Local"
contract="Web.DataService.MyService1.IMyService1"
address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService1.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService2.Local"
contract="Web.DataService.MyService2.IMyService2"
address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService2.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService3.Local"
contract="Web.DataService.MyService3.IMyService3"
address="https://www.mydomain.com/MyVirtualDirectory.Local/MyService3.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<!-- Beta client endpoints -->
<endpoint name="MyService.Beta"
contract="Web.DataService.MyService.IMyService"
address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService1.Beta"
contract="Web.DataService.MyService1.IMyService1"
address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService1.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService2.Beta"
contract="Web.DataService.MyService2.IMyService2"
address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService2.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService3.Beta"
contract="Web.DataService.MyService3.IMyService3"
address="https://www.mydomain.com/MyVirtualDirectory.Beta/MyService3.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<!-- Live client endpoints -->
<endpoint name="MyService.Live"
contract="Web.DataService.MyService.IMyService"
address="https://www.mydomain.com/MyVirtualDirectory/MyService.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService1.Live"
contract="Web.DataService.MyService1.IMyService1"
address="https://www.mydomain.com/MyVirtualDirectory/MyService1.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService2.Live"
contract="Web.DataService.MyService2.IMyService2"
address="https://www.mydomain.com/MyVirtualDirectory/MyService2.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
<endpoint name="MyService3.Live"
contract="Web.DataService.MyService3.IMyService3"
address="https://www.mydomain.com/MyVirtualDirectory/MyService3.svc"
binding="wsHttpBinding"
bindingConfiguration="Binding.Secure"
/>
</client>
</system.serviceModel>
This is very frustrating!
Edits:
I've figured out the exception that I was getting. I had MyService2.Live twice. I fixed this and no longer get the exception. I'd still like to know if I can keep VS10 from changing my App.Config.
You could use the svcutil tool to generate the files and manually merge them with the ones you have modified.
p.s: use slsvcutil if your client is Silverlight
My solutions for the problem ('Update service reference' takes 2 seconds ... svcutil with manual copy paste takes 30 seconds and too much alt-tabs):
If you're on source control (e.g. TFS) ... check in the app or web.config before updating. Then run 'Update service reference'. This will automatically check out the config file. After the update, just 'Undo checkout' from source control should put the original one back, but the generated reference code will be updated.
If not on source control: Open the app or web.config file, select all text (ctrl+a), copy (ctrl+c), update service reference, select all text in the config file again (ctrl+a), paste (ctrl+v).
It takes a few seconds longer, but still less of a hazard than using svcutil, which to be honest I only use when adding a service in the IDE fails and I need some info the dialog won't give me.
Sidenote: If you're adding a service, you should manually add the correct bindings and endpoints for your new service ofcourse.

Deploying WCF Service with both http and https bindings/endpoints

I've written a WCF web service for consumption by a Silverlight app. Initially, the service only required a basic http binding. We now need to be able to deploy the service for use under both http and https. I've found some settings for web.config that allow me to do this as follows:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="CxtMappingWebService.CxtMappingWebServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="SecureHttpBinding">
<security mode="Transport" />
</binding>
<binding name="BasicHttpBinding">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">
<endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Unfortunately, however, there's a problem with this.
This web service needs to be deployed to hundreds of our customers' servers, and not all of them will be using https. Deploying it to a server that doesn't have an https binding set up in IIS causes it to fail. Is there a way to have both of these bindings in the web.config by default without it dying if there's not an https binding set up in IIS?
We've got a possible solution for this problem, but it doesn't really fit well with our deployment requirements.
Has anybody else encountered anything like this before, and how did you resolve it?
The accepted answer on this page is not of much use if you don't use an installer.
The correct answer lies in a later edit by the OP himself, all one needs to do is bind both http and https ports in IIS and then use the configuration below.
<service name="CxtMappingWebService.CxtMappingWebService" behaviorConfiguration="CxtMappingWebService.CxtMappingWebServiceBehavior">
<endpoint address="" bindingConfiguration="SecureHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="" bindingConfiguration="BasicHttpBinding" binding="basicHttpBinding" contract="CxtMappingWebService.ICxtMappingWebService" behaviorConfiguration="SilverlightFaultBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
That worked just fine for me!
In the end, we decided to go with external files using the configSource attribute for the bindings, behaviors, and services sections of the web.config, like so:
<bindings configSource="bindings.config" />
<behaviors configSource="behaviors.config" />
<services configSource="services.config" />
This way, we deploy it by default with those external files set up for http access only, and give the customer instructions (or assist them) on how to edit the external files to set up for https access. This also allows us to deploy future changes to the web.config itself without overwriting the external config files.
This would be handled by the installer you use to deploy the service. It should be a prerequisite (or at least leave an option in the installer) to deploy the both endpoints or only the http one.
Two of your endpoints have the same URI. This is not permitted in WCF. You should be able to specify endpoints with different bindings, but the URI's must be different (i.e. different port number or different contract).

WCF - Beginners question on Address (of ABC)

I am new to WCF. Following is a question on WCF.
Suppose, I have a service defined as follows.
The host has two addresses. I usually click on the base address http://.... to generate proxy.
When the proxy is generated, will it have address of http alone?
How can I generate a proxy with net.tcp.
Is there any article that explains the use of net.tcp with local host and ASP.NET?
Here's my config:
<service name="XXX.RRR.Common.ServiceLayer.MySL" behaviorConfiguration="returnFaults">
<endpoint
behaviorConfiguration="LargeEndpointBehavior"
binding="netTcpBinding" bindingConfiguration="MessagingBinding"
contract="XXX.RRR.Common.ServiceLayer.IMySL" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:86/XXX/RRR/ManagerService" />
<add baseAddress="http://localhost:76/XXX/RRR/ManagerService" />
</baseAddresses>
</host>
</service>
Thanks
Lijo
What exactly is your issue here?? From your config, I see you don't have any address defined on the service endpoint - you need to supply one!
<service name="XXX.RRR.Common.ServiceLayer.MySL" behaviorConfiguration="returnFaults">
<endpoint
address=""
behaviorConfiguration="LargeEndpointBehavior"
binding="netTcpBinding" bindingConfiguration="MessagingBinding"
contract="XXX.RRR.Common.ServiceLayer.IMySL" />
When you create a client proxy against this service using the http address, then yes, the client side config will have the http endpoint as its address - something like:
<client>
<endpoint name="Default"
address="http://localhost:76/XXX/RRR/ManagerService"
binding="basicHttpBinding"
contract="XXX.RRR.Common.ServiceLayer.IMySL" />
</client>
You can simply manually add a second endpoint to the config - or use the Wcf Configuration Tool in Visual Studio to do that! - like so:
<client>
<endpoint name="Default"
address="http://localhost:76/XXX/RRR/ManagerService"
binding="basicHttpBinding"
contract="XXX.RRR.Common.ServiceLayer.IMySL" />
<endpoint name="TCP"
address="net.tcp://localhost:86/XXX/RRR/ManagerService"
binding="netTcpBinding"
contract="XXX.RRR.Common.ServiceLayer.IMySL" />
</client>
However, with the current configuration you have on the service side, you only expose a single netTcp endpoint on the server - so you won't even be able to connect to the server using HTTP to create your client proxy.....

CSLA with WCF nettcpbinding

I am using CSLA.NET. It works realy nice with the wsHttpBinding. Now, I have my own Windows-Service and search the solution, that I can use this Windows-Service as the CSLA-Server and using nettcpbinding. Can someone give me a tip how to going on? Perhaps someone has a sample how I can do that.
Thank you!
Best Regards, Thomas
Basically, you need to do two things:
change your server-side configuration to include an endpoint with the netTcpBinding (this can be in addition to the existing wsHttpBinding endpoint - no problem)
add the netTcpBinding to your client's config file as well and selecting that endpoint when you connect
You should have something like this in your server side config:
<services>
<service name="YourService">
<endpoint name="something"
address=""
binding="wsHttpBinding"
contract="IYourService" />
</service>
</services>
Just add an endpoint for the netTcpBinding:
<services>
<service name="YourService">
<endpoint name="something"
address=""
binding="wsHttpBinding"
contract="IYourService" />
<endpoint name="something"
address="net.tcp://YourServer:7171/YourService"
binding="netTcpBinding"
contract="IYourService" />
</service>
</services>
Now if you're hosting in IIS, you might run into some problems - you need to configure IIS7 (Win2008 or Win2008R2 server), and in IIS6, you won't be able to host your netTcp service in IIS6 :-(
Same thing on the client side - add a second endpoint for netTcp:
<client>
<endpoint name="something"
address="http://YourServer/SomeVirtDir/YourServiceFile.svc"
binding="wsHttpBinding"
contract="IYourService" />
<endpoint name="netTcpEndpoint"
address="net.tcp://YourServer:7171/YourService"
binding="netTcpBinding"
contract="IYourService" />
</client>
and now when you create your endpoint in code, use the named endpoint:
YourServiceClient client = new YourServiceClient("netTcpEndpoint");
That should be all, really (unless CSLA requires something extra which I wouldn't know about.... I know "plain-vanilla" WCF)