我寫了一個相當簡單的小C#web服務,通過WCF從獨立的EXE託管。代碼 - 有點簡化 - 看起來像這樣:如何從Delphi 2007中使用非IIS託管的WCF C#Web服務?
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。
我可以很容易地創建一個使用此服務的Visual Studio 2008客戶端應用程序。沒問題。但是使用Delphi 2007是一個不同的問題。我可以使用Delphi中的WSDL導入器從(在這種情況下)檢索WSDL http://bernard3:8000/VMWareProvisioning/Service?wsdl導入單元編譯得很好。我必須手工初始化代理由於WSDL不包含一個URL(注意額外「/ CoreServices」如圖所示的C#代碼):
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);」。錯誤是「無法處理該消息,因爲該內容類型‘文本/ XML;字符集=‘UTF-8’不是預期的類型’應用/肥皂+ xml的;字符集= UTF-8」
我懷疑我在某個地方出現了一個愚蠢的小錯誤,可能是在導入WSDL或連接選項時出現錯誤。誰能幫忙?
你知道我可以在哪裏下載最新的WSDLImp.exe嗎?我檢查了Embarcadero網站,但找不到任何超出它的錯誤修復引用。 – 2009-07-21 14:46:42