How to send WCF's ClientCredentials using Delphi XE - wcf

I've developd a WCF Service with a custom UserNamePasswordValidator with a basicHttpBinding using HTTPS. It works great with a .Net client, using ClientCredentials to send the username and password for authentication.
However, I need to call this from a Delphi XE client. How to I send the equivalent of .Net ClientCredentials using Delphi? Is that possible? If it is, how? If it is not, are there alternatives?
Tks
EDIT
Below is my client side code in .Net:
EndpointAddress oTransac = new EndpointAddress(GetAddress());
using (WebServiceClient oClient = new WebServiceClient ("httpbasic", oTransac))
{
oClient.ClientCredentials.UserName.UserName = "username";
oClient.ClientCredentials.UserName.Password = "password";
oClient.DoStuff();
}
EDIT
I've been doing some research, and I've been able to do authentication between Delphi and old asmx web services using SOAP Hearders. I found the article below. Will I be able to achieve the same behavior of the old [WebMethod] [System.Web.Services.Protocols.SoapHeader("SoapHeader")] using the article's technique?
http://weblogs.asp.net/paolopia/archive/2008/02/25/handling-custom-soap-headers-via-wcf-behaviors.aspx
EDIT BOUNTY
The get marked as the correct answer of the bounty, I would like to be able to call the web service from Delphi using WCF Service UserNamePasswordValidator on the server side.

First, basicHttpBinding is over HTTP (not HTTPS)
http://msdn.microsoft.com/en-us/library/ms731361.aspx
To consume a WFC service from Delphi is usually done by producing a WSDL from the service
How to create a single WSDL file from existing WCF service?
http://social.msdn.microsoft.com/Forums/en/wcf/thread/fc2c5074-1116-4f92-a972-01bb3a142535
WCF: how to generate a single WSDL document, without WSDL:import?
and generating a Delphi proxy class by importing that WSDL into your Delphi project.
>wsdlimport.exe service.wsdl
and then use the generated Delphi unit in your Delphi project
http://www.drbob42.com/examines/examinB9.htm
http://edn.embarcadero.com/article/36962
The parameters you send to service calls (username, password, ClientCredientials, etc) will be defined in the generated Delphi unit - should be no problem as long as you can connect to the service.

Some weeks ago I also had to connect to a WCF service. I ended up writing the client in .net and using UnmanagedExports
https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports
The dll can then be consumed in Delphi like a native dll

Related

Can I communicate to a WCF (svcutil) web service using just GET or POST?

I have been given access to a WCF/WSDL web service. I first do this:
svcutil.exe https://<thedomain>/foo/foo.svc?wsdl
to generate the C# class I need. I then plug this class into my C# application and it works fine. Note that I did not develop this server and cannot change it.
Question is this:
How can I communicate with this server without svcutil? I prefer to use just REST (GET and POST).
This way I would be able to connect to it from a Linux or Mac machine, not just Windows.
Update In my C# code, this is what happens:
WSHttpBinding binding = new WSHttpBinding();
EndpointAddress endpoint = new EndpointAddress("<address>");
fooClient client = new fooClient(binding, endpoint);
//(fooClient class came from svcutil)
//I now work with fooClient, call methods on it, etc.
That depends on the bindings in use by the service.
The "default" (read: most commonly used) bindings (basicHttp and wsHttp) implement SOAP 1.1 and SOAP 1.2 respectively, which means you're talking HTTP to the service, but using a specially crafted XML envelope in which your payload must be wrapped.
When the webHttpBinding is applied, you can talk "plain old XML" or JSON to the service, how to do so depends on the applied UriTemplate.
Note that there's no standardized metadata exchange for REST services (at least not as far as WCF is concerned), so even if the service is exposed using a REST binding, the information about how to construct the calls will not be exposed automatically but must instead be documented by the owners explicitly.
REST is an architectural approach. WCF service should be built for REST, not that you just can use it like this. In WCF service "by default" all requests are POSTs.

Silverlight, WCF Ria, EF, flow

Can someone please explain to my how the flow is when i have a Silverlight Application that uses WCF Ria and Entity framework. So I better understand where to secure the transport of information.
I think of it as, the user enter the website and the silverlight application is downloaded to the users computer. Then if the user what to create a new entry, he enter the details, and then a new instance of the service is create. The service is on the web project with the silverlight application. Then the information is sent to the webservice on the web project, and from the webservice the information is sent to the server where the DAL is.
All the information is sent in XML.
And i have to secure it from the user to the web service, and from the webservice to the server where the DAL is.
Am I right, or is it completely wrong?
Thanks
The best way I founded to cypher data between client and server with WCF was setting the EnableClientAccess to require a secure endpoint in the DomainService:
[EnableClientAccess(RequiresSecureEndpoint = true)]
public partial class DomainService : LinqToEntitiesDomainService<YourEntities>

Are client service contracts still autogenerated in WCF 4.0?

I have a net.tcp binding example that apparently dates back to .NET 2.0 runtime version. The client code of the WCF Net.TCP binding example has an interface marked as "System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "2.0.x.x") or so.
it also defines some Request & Response classes where the request apparently wraps the parameters of the service operation contract and the Response class wraps the result/return value. And it also defines a controller class for the service.
Now, in a WCF hosted by winform with net.tcp binding, I have found no way to autogenerate these classes myself. I wonder, is that an old way of doing things? is it required? or can I just include in the client app a reference to the DLL that contains the service?
I made some changes and now nothing works and wondered if I can just get rid of those "autogenerated" classes (or if not, HOW can I regenerate them?).
I use Visual Studio 2012 Ultimate for .NET 4.5 under Windows 7 Ultimate. My application are two winforms (client and server) that use WCF with netTCP binding.
Apparently I have to point svcutil o the base address rather than that of the service or endpoint. Then it will generate the client code and config.

consuming WCF service in .net 2.0 windows application

I'm new in WCF service and I need to consume the WCF service from my client for my current .net 2.0 windows app. I successfully added the WCF service as web reference in my .net 2.0 application but when using the web method of the service it took long time to execute the method and in the end my application is not responding. Base on the request in fiddler, the request has been timed out. My client provides me a user name and password but I don't know where to use it. Base on the wcf web service wsdl of my client, it uses WSHttpBinding.
I also created a sample .net 4.0 windows application and added the service as reference but still cannot use the web method. I check also the request in fiddler and gives me a response error "The request for security token could not be satisfied because authentication failed.".
Please help. I need to consume the WCF service using my existing .net 2.0 application.
Thank you very much in advance!
If you want to consume your WCF service from .NET 2.0 via adding web reference you must use BasicHttpBinding - that is only backward compatible build-in binding (except custom defined binding) with ASMX based client.
Your exception in case of .NET 4.0 test complains about security token - WsHttpBinding uses Windows security by default. It is hard to diagnose the problem further because you didn't provide enough information.

Consume WCF Service Hosted in a Windows Service

I wrote the WCF Service and hosted in windows service. I need to know how to consume this windows service in my client application.
Note:
I wrote Net pipe binding service.
Edit:
How can I write the client application for net pipe binding?
You need to do a few easy steps:
start your Windows service hosting your WCF service
from within Visual Studio (2008 or higher), right-click on a project node in the solution explorer and choose "Add service reference"
enter the URL where your service can be reached
That's about all there is, really. Visual Studio will go to your running service, get all the metadata it needs (assuming you've enabled a MEX endpoint for metadata exchange), and will create a client proxy class for you to use to connect your client to your service.
Marc
you need to use ChannelFactory to create a proxy, and then you can use the proxy to perform wcf tasks.
ChannelFactory<IWCFService> pipeFactory = new ChannelFactory<IWCFService>(
new NetNamedPipeBinding(),
new EndpointAddress("net.pipe://localhost/PipeWCFService"));
IWCFService pipeProxy = pipeFactory.CreateChannel();
pipeProxy.RunWCFServiceMethod();}
http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication
You can consume it like any other WCF service. The method used for hosting the WCF service is not relevant to the client side.
If you need details on how to actually build the client, let me know and i'll update the post.
Edit : Start here to learn how to build a WCF client.