How to send WCF's ClientCredentials using Delphi XE

这一生的挚爱 提交于 2019-12-10 03:12:26

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6095887/how-to-send-wcfs-clientcredentials-using-delphi-xe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!