I'm working on a web application using mvc, we have already a service that does http binding, the client wants tcp binding for certain actions (not really sure why) but it's their requirement so i'm attempting to set up net.tcp binding, all references i am seeing to doing this involve a windows application and not a web application.
I guess my question has 2 parts, first can you run httpbinding and net.tcp binding at the same time through the same service/project.
secondly how would I consume the service through a webproject?
From "Programming WCF Services"
http://www.amazon.de/Programming-WCF-Services-Mastering-AppFabric-ebook/dp/B0043D2DUK/ref=sr_1_fkmr0_1?ie=UTF8&qid=1408811647&sr=8-1-fkmr0&keywords=programming+wcf+services+3d+edition
Every service is associated with an address that defines where the service is, a binding
that defines how to communicate with the service, and a contract that defines what the
service does. This triumvirate governing the service is easy to remember as the ABC of
the service. WCF formalizes this relationship in the form of an endpoint. The endpoint
is the fusion of the address, contract, and binding.
So, in your case you'll need to define 2 endpoints for your service.
Example from the same book:
<service name = "MyService">
<endpoint
address = "http://localhost:8000/MyService"
binding = "wsHttpBinding"
contract = "IMyContract"
/>
<endpoint
address = "net.tcp://localhost:8001/MyService"
binding = "netTcpBinding"
contract = "IMyContract"
/>
<endpoint
address = "net.tcp://localhost:8002/MyService"
binding = "netTcpBinding"
contract = "IMyOtherContract"
/>
</service>
On the client side you'll need to "Add service reference" in VS and provide an address of the desired endpoint.
http://msdn.microsoft.com/en-us/library/bb628652.aspx
1) Yes, you can set up both HTTP and a net.tcp endpoints (each of which will require it's own metadata exchange endpoints) within a service. More details here.
2) In your web application project, right click on References then click on Add Service Reference. In the dialog, copy the endpoint address of the net.tcp service. Enter the desired namespace and click ok.
Related
I am consuming a web service through the debug mode in VS2013 in my project, if 14 records are there but not coming,
But when consuming via WCF Test Client, records are coming ,
please anybody can suggest me what would be the case in here ?,
configurations and service url are same,
web configuration
<endpoint address="http:/localhost:8080/SCP/Apis/Admin/Services/UserService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserService" contract= "AdminUserService.IUserService" name="BasicHttpBinding_IUserService" />
and I call to service client like this.
var dto = new UserServiceClient().GetActiveUsers().ToList();
By default AppFabric adds WorkflowControllEndpoit with NetNamedPipeBinding.
In my environment I need to manage workflows from another server which means that I cannot use net.pipe.
How do I add a WorkflowControllEndpoint on HttpBinding?
Please note that I allow users to dynamicly add workflows so I'm looking for a way to add endpoint to all workflows hosted by AppFabric. tag in web.config is not good for me.
Attempt 1:
Using behaviour to add endpoint. I've had problems adding WorkflowControllEndpoint. I've add following to behavior
var host = (WorkflowServiceHost)serviceHostBase;
host.AddServiceEndpoint(new WorkflowControlEndpoint(new
WSHttpBinding(), new EndpointAddress(host.BaseAddresses[0] +
"/Control")));
that compiles and runs but when I make request to this endpoint I'm getting
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost/WorkflowServices/xx.xamlx/Control. The client and service bindings may be mismatched.
I guess that's because endpoint wasn't added and it goes to a default endpoint which doesn't accept Soap
Attempt 2
Disabling net.pipe - That forces AppFabric to bind to WSHttpBinding for WorkflowControllEndpoint but then I get wornings in Persistence window like
workflow persistence is not fully functional because the net.pipe
What functionality do I loose ?
I am working on a task where I have to list the number of applications calling our web/wcf services.
Currently I am looking into the applications folders structure, and looking for the folder "Web References" to list all web services.
But this way of finding the total list for WCF services does not work because WCF services can be consumed in many other ways.
Is there a foolproof way of doing this?
One of ways would be implementing your own message inspector on server, deriving from
IDispatchMessageInspector, and logging IP address of every request
(see example here).
If you need more detailed information, for example, if there are multiple clients
on one machine - you need to include client identification into your contract,
and send it either in custom headers, or implement authentication.
But of course, this does not prevent multiple clients from using same identity.
You can add custom headers to client configuration.
<endpoint address="http://localhost:8080"
binding="basicHttpBinding"
contract="CalService.ICalService">
<headers>
<ClientIdentification>Cal1</ClientIdentification>
</headers>
</endpoint>
And retrive that using following code
var operationContext = OperationContext.Current;
var requestContext = operationContext .RequestContext;
var headers = requestContext.RequestMessage.Headers;
int headerIndex = headers.FindHeader("ClientIdentification", "");
var clientHeaderString = headers.GetHeader<string>(headerIndex);
see this also.
Has any one ever implemented a custom serializer in WCF ? The reason i want to replace the WCF default serializer with custom serializer is to call different services from the same wcf proxy client.I would be glad if some one can suggest a way to do this ?
I did something similar on a project I recently did.
However I did have 2 different WCF clients. How I "switched" was I then created a shared interface between the clients and then used a ServiceLocator to fetch the IClient.
Does this make sense?
If I understand the problem correctly you have an application that you want to talk to one of two services that use the same interface based on some criteria. The services have different configurations so you cannot reuse the same config.
To tackle this I would setup the two configurations in the application config, it could also be done in code if you wish.
<client>
<endpoint address="http://service1"
binding="basicHttpBinding"
bindingConfiguration="Service1Binding"
behaviorConfiguration="Service1Behavior"
contract="IServiceInterface, Service"
name="Service1"/>
<endpoint address="http://service2"
binding="basicHttpBinding"
bindingConfiguration="Service2Binding"
behaviorConfiguration="Service2Behavior"
contract="IServiceInterface, Service"
name="Service2"/>
</client>
In your code you then need some sort of conditional statement to determine which service you want to talk to. Once you have done this you can create a ChannelFactory for the required configuration.
string serviceName = FullMoon ? "Service1" : "Service2";
var channelFactory = new ChannelFactory<IServiceInterface>(serviceName);
var proxy = channelFactory.CreateChannel();
proxy.SomeServiceCall();
channelFactory.Close();
If you are using IoC to inject the proxy you will probably need to push this into some sort of factory. You can also look at optimizing this as creating the ChannelFactory is the expensive part, it is possible to create the Factory without specifying the configuration just the contract. You would then need to specify the binding and the endpoint when you create the channel.
Learning WCF (I know, late to the party)
I am working through Juval Lowy's Programming WCF book. I see that I can configure multiple endpoints (including URI's) for my service.
However, when I host these in IIS, only the location of the .svc file seems to matter. Is the multiple endpoints/addresses thing only applicable if you are self-hosting? Am I missing something about hosting services in IIS?
"only the location of the .svc ", you're heading to this because baseaddress are provided by IIS in case of web-hosting (IIS hosting) unless you're using CustomServiceHostFactory. Then whatever value you provide in address, are appended to baseaddress (.svc/..)
You needs to give several host name in IIS for the the same WCF and set several endpoints in the client section of web.config as:
<client>
<endpoint address="hostname1/myservice.svc" ... />
<endpoint address="hostname2/myservice.svc" ... />
<endpoint address="hostname3/myservice.svc" ... />
</client>
Then you can consume them as:
hostname1/myservice.svc
hostname2/myservice.svc
hostname3/myservice.svc