Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to consume non-IIS hosted, WCF, C# web service from Delphi 2007?
    text
    copied!<p>I've written a fairly simple little C# web service, hosted from a standalone EXE via WCF. The code - somewhat simplified - looks like this:</p> <pre><code>namespace VMProvisionEXE { class EXEWrapper { static void Main(string[] args) { WSHttpBinding myBinding = new WSHttpBinding(); myBinding.Security.Mode = SecurityMode.None; Uri baseAddress = new Uri("http://bernard3:8000/VMWareProvisioning/Service"); ServiceHost selfHost = new ServiceHost(typeof(VMPService), baseAddress); try { selfHost.AddServiceEndpoint(typeof(IVMProvisionCore), myBinding, "CoreServices"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy12; selfHost.Description.Behaviors.Add(smb); // Add MEX endpoint selfHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex"); selfHost.Open(); Console.WriteLine("The service is ready."); Console.ReadLine(); </code></pre> <p>The rest of the C# code; the class VMPService above implements VMProvisionCore.IVMProvisionCore.</p> <pre><code>namespace VMProvisionCore { [ServiceContract(Namespace = "http://Cisco.VMProvision.Core", ProtectionLevel = System.Net.Security.ProtectionLevel.None)] public interface IVMProvisionCore { [OperationContract] bool AuthenticateUser(string username, string password); } </code></pre> <p>I can easily create a Visual Studio 2008 client application that consumes this service. No problems. But using Delphi 2007 is a different issue. I can use the WSDL importer in Delphi to retrieve the WSDL from (in this case) <a href="http://bernard3:8000/VMWareProvisioning/Service?wsdl" rel="noreferrer">http://bernard3:8000/VMWareProvisioning/Service?wsdl</a> The import unit compiles just fine. I have to initialize the proxy by hand since the WSDL doesn't contain a URL (notice the extra "/CoreServices" as shown in the C# code):</p> <pre><code>var Auth: AuthenticateUser; AuthResponse: AuthenticateUserResponse; CoreI: IVMProvisionCore; begin CoreI:= GetIVMProvisionCore(False, 'http://bernard3:8000/VMWareProvisioning/Service/CoreServices'); Auth:= AuthenticateUser.Create; try Auth.username:= 'test'; Auth.password:= 'test'; AuthResponse:= CoreI.AuthenticateUser(Auth); finally FreeAndNIL(Auth); end; </code></pre> <p>The above code will generate an error when it hits the "CoreI.AuthenticateUser(Auth);". The error is "<strong>Cannot process the message because the content type 'text/xml; charset="utf-8" was not the expected type 'application/soap+xml; charset=utf-8.</strong>"</p> <p>I suspect that I've got a stupid little error somewhere, perhaps during the import of the WSDL or in the connection options or something. Can anyone help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload