WCF service Single proxy instance with multiple endpoints - c#

I developed a WCF Service hosted in a Windows Service which would send a request to the thirdparty webservice and expects a response.So all i would be given is the url/wsdl information of the thirdparty service where its hosted.
I want to implement say a test service which would give response to my request and Create a single proxy of that service by adding service reference in the visual studio to the actual service.So there can be any number of third party applications which would provide their urls in the future for communication.
My question about the WCF is can i create a single proxy client once and just send the request to a webservice based on the url on the fly ? Is it possible to use the same proxy client for both HTTP and HTTPS by just passing the binding and address parameters dyanmically ?

Once you have create the proxy you cannot change its address. You could have several open proxies, one per 3rd party. In addition a single proxy cannot be reused for http and https since they use different bindings (in addition to the reason above).
One reason for this behavior (which may or may not be relevant in your case) id that proxy can keep state with the server, for example an open security session.

Related

Need to get at the data sent to a web service thru the wsdl service reference (Windows c#)

This is a difficult one so hoping someone has been here before with this.
Long story short - we have several hundred web services in projects that use Microsoft's "Add Service Reference" to generate methods from the wsdl.
We now need to push these thru another service first and relay on the call to the original server and do the same with the response.
We have a service that takes soap requests (XML) and does this already so want to reuse this if possible.
How do we get at the SOAP request data either via intercepting the web service call (redirect to stream or file etc.) or see what it would have generated as SOAP XML.
We have no way of using current software to redirect these calls so need a bespoke solution as we need also to track everything going thru the re-director.
The existing rerouting service takes a SOAP XML and passes to another URL and works well for a different project - so we just need the SOAP XML produced by the web service call and we can reuse the service.
//Example call to a simple wsdl generated interface...
Calc.CalculatorSoapClient clc = new Calc.CalculatorSoapClient();
clc.Open();
int x = clc.Add(1, 2); // need to get soap that would have been sent to the web service here
clc.Close();

ASMX Web service call its own instance located at different location

I have one service located at US servers say
http://myservice/ProfileManagerWS/ProfileMGRWS.asmx
When any client make a call, I need to check request header property. If property say its a call for Canadian instance, then redirect call to http://ca-myservice/ProfileManagerWS/ProfileMGRWS.asmx
Previously service was only located at US servers and we have hosted service into Canadian servers just now.
We do not want to make any code changes at consumers of
http://myservice/ProfileManagerWS/ProfileMGRWS.asmx
Should I write HTTPModule or soap extension for US instance?
Also, should I add proxy to US instance to call Canadian instance?
First of all, unless your client application has functionality that will accept a redirect response you won't be able to alter your web service get that functionality.
What you would probably want to do is to implement Geographical Load Balancing at your DNS server. If a Canadian requests the IP address for myservice, give them an IP address that goes to your Candian server that is also configured to accept requests for the myservice domain.

WCF Application EndPoint

I quote from the MSDN:
application endpoint
An endpoint exposed by the application and that corresponds to a service contract implemented by the application.
Can somebody please explain this definition for me? Is the application endpoint the same as the service reference created by the Visual Studio?
All communication WCF service occurs through the endpoints. It provide clients access to the functionality offered by a WCF service.
Each endpoint consists of three properties:
Address (Where)
Binding (How)
Contract (What)
Endpoints can also have a set of behaviors that specify local implementation details.
endpoints concept exists both on clients and services :
A WCF services can expose multiple endpoints and a client may communicate with services with multiple endpoints.
Can somebody please explain this definition for me? Is the application
endpoint the same as the service reference created by the Visual
Studio?
When you add a service reference, Visual Studio will add a new client endpoint in your application (check updated config file). However, Visual Studio will try first to download metadata in order to list all available endpoints for an address.
Basic Explanation:
The application endpoint is the address that your clients will connect to to get to an instance of a service that implements the listed "service contract".
Further Explination:
WCF works through Interfaces, not classes. Each one of those Interfaces is known as a "Service Contract". A single class could implement more than one Interface so two service contracts could be hosted by a single class. You did not ask about this, but I thought I should get that out there too.
To answer your question, a single Interface can be connected to in multiple ways. Each of those ways you create are called Application Endpoints. Here is a practical example: You may want people to be able to connect using either HTTP for external connections or named pipes for requests generated on the same machine for higher performace. By setting up two endpoints up for a single "Service Contract" that lets you have that flexibility.

How to setup WCF proxy relay service

I am writing an ASP.net Dashboard application in C#. The application will collect alarm statistics and display them on the dashboard via Ajax(jQuery).
The application could collect the alarm stats cross domain so we chose to set it up as follows:
A standalone Windows Service runs with a constant connection to the Broker(a program that collects stats). Inside the Windows Service we've hosted a WCF service. The windows service will load pass the string of stats into the WCFExternalService.
We then setup an WCF Service hosted in IIS and referenced inside the Client app( this service will act as a relay/proxy service).
Can someone please point me to an article or explain how to setup the bindings/endpoints to connect the proxy service to the external WCF service?
Thanks in advance for any help on this!
Larry
Looks like you have already got most of the structure going. My inputs below:
The WCF proxy (in UI layer) could implement the same service contract as its WCF service counterpart (in Windows service). However, the WCF proxy would be a 'client' of the real WCF service (you need to configure this in Web.config).
Now, enable the WCF proxy to be consumed by jQuery / JavaScript using WebInvoke attribute. [WebInvoke("GET", WebMessageBodyStyle.WrappedRequest, ResponseFormat:=WebMessageFormat.Json)]
Use jQuery $.ajax syntax to consume your WCF proxy. The url should be an equivalent of 'http://myHost/myVirtual/MyProxy.svc/MyMethod' and the data should be a JSON string equivalent of your WCF proxy parameters.
Further explanation on the first point:
This MSDN article explains how to set up a WCF client (to be consumed by your proxy WCF).
Next, you can create a proxy WCF service to consume the WCF client.
The Web.config of your website (which contains the proxy) needs sections for WCF client and WCF proxy.
Hosting does not matter in WCF, so your 'real' service could support any binding (Http, Tcp) based on your requirements and environment

Send SWT token to a generated wcf proxy and validate it

I've got an WP7 application who does authentication with Azure Access Control Service and stores it's SimpleWebToken in an the IsolatedStorage. I want to use this SWT-token to secure my (locally deployed not in AZURE)WCF Service. (The WCF service is finished, except the ACS token validation part) So I've added an Service Reference in my WP7 application and now I want to send the SWT-token to WCF Service via the generated WCF proxy client, but how? Or is this not the way to do it?
Because custom binding & wsHttpBinding isn't supported on WP7(Not sure if mango fixes this) and I don't want to use a WCFDataService. I've come with an nasty solution, I will add a string(the simplewebtoken) to my operationcontract and send it with every client call. I validate this token in the serviceimplentation with the configured securityTokenHandler. This currently works for me!

Categories

Resources