【发布时间】:2009-07-09 02:36:59
【问题描述】:
我编写了一个相当简单的小型 C# Web 服务,通过 WCF 从独立的 EXE 托管。代码 - 有点简化 - 看起来像这样:
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();
其余的 C# 代码;上面的 VMPService 类实现了 VMProvisionCore.IVMProvisionCore。
namespace VMProvisionCore
{
[ServiceContract(Namespace = "http://Cisco.VMProvision.Core", ProtectionLevel = System.Net.Security.ProtectionLevel.None)]
public interface IVMProvisionCore
{
[OperationContract]
bool AuthenticateUser(string username, string password);
}
我可以轻松地创建一个使用该服务的 Visual Studio 2008 客户端应用程序。没问题。但是使用 Delphi 2007 是一个不同的问题。我可以使用 Delphi 中的 WSDL 导入器从(在这种情况下)http://bernard3:8000/VMWareProvisioning/Service?wsdl 检索 WSDL。导入单元编译得很好。我必须手动初始化代理,因为 WSDL 不包含 URL(请注意 C# 代码中显示的额外“/CoreServices”):
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;
上面的代码在点击“CoreI.AuthenticateUser(Auth);”时会产生错误。错误是“无法处理消息,因为内容类型 'text/xml; charset="utf-8" 不是预期的类型 'application/soap+xml; charset=utf-8.”
我怀疑我在某个地方遇到了一个愚蠢的小错误,可能是在导入 WSDL 期间或在连接选项中或其他地方。有人可以帮忙吗?
【问题讨论】:
标签: c# wcf web-services delphi