How to Consume WCF Service in Service Reference if it has multiple Endpoint with name - wcf

I have very specific question..
If i create one WCF Service and it has multiple endpoints with the name how can i access that using browser ?
Also How can i access that in my client application via Add Service Reference ?
like my config code:
<services>
<service name="MultipleEndpoint.SampleService" behaviorConfiguration="MultipleEndpoint.SampleService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:55052/SampleService.svc"/>
</baseAddresses>
</host>
<endpoint address="/basic" binding="basicHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="basicBinding" >
</endpoint>
<endpoint address="/wsHttp" binding="wsHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="wsBinding" >
</endpoint>
<endpoint address="/webHttp" binding="webHttpBinding" contract="MultipleEndpoint.ISampleService" behaviorConfiguration="REST">
</endpoint>
</service>
</services>
Now, when i tried to access that using
http://localhost:55052/SampleService.svc/basic or
http://localhost:55052/SampleService.svc/wsHttp
it gives me page/ resource not found IE Standard Error Message...
Same time i like to know how would i add this type of url as a service reference in my client application ?

Those service addresses are different and they are not strictly needs to be brow-sable, means you can't browse a service for an endpoint like http://localhost:55052/SampleService.svc/basic. Those addresses are used to distinguish endpoints in communication.
If you see the wsdl of the service all the addresses of those endpoints are specified there.
If you create the proxy of the service through "Add Service Reference" all the endpoints are created in the configuration separately like..
<client>
<endpoint address="http://localhost:54671/Service1.svc/basic"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
<endpoint address="http://localhost:54671/Service1.svc/ws" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1">
</endpoint>
...
</client>
Say if you want to talk to the service using the basic http endpoint then you can create the proxy for that by passing the corresponding endpoint configuration name in the ctor.
Ex.
// this will uses the basic http endpoint.
Service1Client client = new Service1Client("BasicHttpBinding_IService1");

Related

How to stop exposing multiple endpoint at client side in WCF

suppose my wcf has many end point with different binding.so when user / client add service ref from VS IDE at then multiple endpoint related data expose & added in client config file at client side.
Can we design service in such a way as a result only one endpoint related address will be revealed at client side?
Suppose I have one service with HTTP & TCP related endpoint and I want when external customer will add our service from their VS IDE then they will see our HTTP endpoint address not TCP. So guide me how could I do this? How to design service end config file for my requirement?
here i am attaching a small sample code for multiple endpoint related in config file.
<services>
<service behaviorConfiguration="MulContractService" name="MyWCFLibrary.MultipleContract">
<clear />
<endpoint binding="basicHttpBinding" bindingConfiguration="MulContractBasicBinding"
name="MulContractBasicEndPoint" contract="MyWCFLibrary.IMultipleContract"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IByeWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IHelloWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:8733/Design_Time_Addresses/MyWCFLibrary/MultipleContract/"
binding="netTcpBinding" bindingConfiguration="MulContractTCPBinding"
name="MulContractTCPEndPoint" contract="MyWCFLibrary.IMultipleContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MyWCFLibrary/MultipleContract/" />
</baseAddresses>
</host>
</service>
</services>
EDIT
here i am giving my new full code and just guide me does it work?
namespace CustomService
{
[ServiceContract]
public interface IEmp
{
[OperationContract]
string GetEmp();
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class BusinessLayer : IEmp
{
public BusinessLayer()
{
}
public string GetEmp()
{
return "Casino";
}
}
}
Config code at service end
<services>
<service name="CustomService.BusinessLayer">
<endpoint address="CustomerFactory" binding="basicHttpBinding"
bindingConfiguration="HTTPBindingConfig" name="CustomerFactoryHTTP"
contract="CustomService.IEmp" listenUriMode="Explicit" />
</service>
<service name="CustomService.BusinessLayer">
<endpoint binding="basicHttpBinding" bindingConfiguration="HTTPBindingConfig"
name="CustomerMasterHTTP2" bindingName="CustomerMaster" contract="CustomService.IEmp" />
</service>
</services>
just tell me the above config will work?
in the above config i define two service tag with same name because my service full name with namespace is CustomService.BusinessLayer
is it ok or do i need to give unique name for each service tag?
my intention is i will have same service but with multiple service tag and when customer will add my service ref at their end then they will not be able to see all the endpoint.
my intention is not expose all endpoint & address to every client.
so guide me what i have done does it work or not....if not then rectify my config entry and tell me how could i restrict my endpoint not to expose each binding & address before all client. thanks
Maybe not what you are looking for but you could easily add another service to your project and give it the endpoints you want your client to see. Then the existing service could be just for TCP or for both types. Under the covers of course both services would run the same code.
Adding a service is just like adding any other file, right click, add New Item, WCF service. Then you can use the WCF configuration Editor to configure it if you dont want to do it by hand.
For what it is worth here is a config with two services. You can see that the first service has two endpoints, an Http and a TCP while the second service exposes just the http endpoint. Your two services would then each implement IService and would delegate to a common class or library.
<services>
<service name="Mynamespace.Service1">
<endpoint binding="basicHttpBinding"
bindingConfiguration="HTTPBindingConfig" name="MyserviceHTTP"
contract="Mynamespace.IService" listenUriMode="Explicit">
</endpoint>
<endpoint binding="netTcpBinding"
bindingConfiguration="TCPSecured" name="MyserviceHTTP"
contract="Mynamespace.IService" />
</service>
<service name="Mynamespace.Service2">
<endpoint binding="basicHttpBinding"
bindingConfiguration="HTTPBindingConfig" name="MyserviceHTTP"
contract="Mynamespace.IService" listenUriMode="Explicit">
</endpoint>
</service>
</services>

WCF EndPoints not working with IIS hosting

I have following settings
<services>
<service name="HelloWCFServiceClass.clsHelloWCFServiceClass" >
<host>
<baseAddresses>
<add baseAddress="http://localhost:6789/IISHosting/HelloWorldISSHostedService.svc"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="HelloWCFServiceContract.IHelloWCFServiceContract" />
<endpoint address="/test" binding="basicHttpBinding"
contract="HelloWCFServiceContract.IHelloWCFServiceContract"/>
</service>
</services>
I can open
http://{ServerName}:6789/HelloWorldISSHostedService.svc
But I'm getting an error
The webpage cannot be found
while trying to access through end point like this
http://{ServerName}:6789/HelloWorldISSHostedService.svc/test
You're using BasicHttpBinding - that's a SOAP binding, you cannot just use your browser to browse to that endpoint.
You'll need to use something like SoapUI to test your SOAP services.
If you want a service that's testable in your browser (by just navigating to an URL), you need to use the webHttpBinding instead (REST service)
If your service is part of an MVC project, you need to configure your routing table
http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs

WCF Basics - Endpoints

I'm wondering about the address="" section in the web.config file
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="user">
<endpoint address="" behaviorConfiguration="ptUserAspNetAjaxBehavior" binding="webHttpBinding" contract="IUser" />
</service>
</services>
<services>
<service behaviorConfiguration="MyServiceTypeBehaviors" name="controller">
<endpoint address="" behaviorConfiguration="ptUserAspNetAjaxBehavior" binding="webHttpBinding" contract="Icontroller" />
</service>
</services>
I'm adding a second service that I will be calling via jQuery. My first service worked great. As you can see the endpoint address is blank. I'm adding the second service and I'm wondering first if I'm doing it correctly? Can I create a new service tag using the same behaviorConfiguration, and binding but with a different contract?
This spawned another question about the address in the web.config file.
Why does it work when it is = "" and why would I want to use an address?
It will work with address="" when
you host your service in IIS and basically IIS's virtual directory dictates the URL of your service (the vdir where your *.svc file exists). Thus if you have two separate services, with two separate *.svc files, then each entry in the configuration can have an address="" setting. But you cannot have two endpoints for the same service and both have the empty address attribute
or:
you have a base address defined for your service in your config and thus that endpoint will use that base address for its service address

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)