在Delphi Win32 Client中使用WCF服务(basicHttpBinding)时出现问题

时间:2022-06-01 22:17:47

I am trying to make a Delphi client (Delphi 2006) to communicate with a service written using WCF. Service is damn simple with just one function. Technically like below:

我正在尝试使用Delphi客户端(Delphi 2006)与使用WCF编写的服务进行通信。只需一个功能,服务非常简单。技术上如下:

[ServiceContract (Namespace = "http://www.company.com/sample/")]
public interface IService
{
    [OperationContract]
    string GetNumber (string name);
}

I have hosted this service on IIS and exposed it using basicHttpBinding with mex end point. I am able to use it in .NET clients.

我已在IIS上托管此服务,并使用带有mex端点的basicHttpBinding公开它。我可以在.NET客户端中使用它。

I tried to run WSDLImp.exe and it generated a source code unit (btw, it generates wierd classes to encapsulate string type. Why cant it be same as Delphi string type?). When I try to call this service, I get the exception:

我试图运行WSDLImp.exe并且它生成了一个源代码单元(顺便说一句,它生成了用于封装字符串类型的奇怪类。为什么它不能与Delphi字符串类型相同?)。当我尝试调用此服务时,我得到异常:

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。

I don't see any way to configure the Delphi Win32 client to changing the binding or security parameters. How can I fix this problem?

我没有看到任何方法配置Delphi Win32客户端来更改绑定或安全性参数。我该如何解决这个问题?

2 个解决方案

#1


I've had the exact same problem. Delphi just has hard time importing the WSDL exposed by WCF. One solution is to add an ASMX wrapper to your service and use that with Delphi clients.

我有完全相同的问题。 Delphi很难导入WCF公开的WSDL。一种解决方案是将ASMX包装器添加到您的服务中,并将其与Delphi客户端一起使用。

Here's an example:

这是一个例子:

[ServiceContract (Namespace = "http://www.company.com/sample/")]
public interface IService
{
    [OperationContract]
    string GetNumber (string name);
}

public class Service : IService
{
    public string GetNumber (string name)
    {
        return Repository.GetNumber(name);
    }
}

[WebService(
    Namespace = "http://www.company.com/sample/",
    Name = "wstest",
    Description = "description")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AsmxService : WebService
{
    [WebMethod]
    public string GetNumber(string name)
    {
        return Repository.GetNumber(name);
    }
}

#2


You need to look at the network traffic between the client and service to see what's going on. Alternatively, turn on WCF tracing on the service, possibly including message tracing. You should be able to see what's going on, in great detail.

您需要查看客户端和服务之间的网络流量,以查看正在发生的情况。或者,在服务上启用WCF跟踪,可能包括消息跟踪。您应该能够非常详细地了解正在发生的事情。

#1


I've had the exact same problem. Delphi just has hard time importing the WSDL exposed by WCF. One solution is to add an ASMX wrapper to your service and use that with Delphi clients.

我有完全相同的问题。 Delphi很难导入WCF公开的WSDL。一种解决方案是将ASMX包装器添加到您的服务中,并将其与Delphi客户端一起使用。

Here's an example:

这是一个例子:

[ServiceContract (Namespace = "http://www.company.com/sample/")]
public interface IService
{
    [OperationContract]
    string GetNumber (string name);
}

public class Service : IService
{
    public string GetNumber (string name)
    {
        return Repository.GetNumber(name);
    }
}

[WebService(
    Namespace = "http://www.company.com/sample/",
    Name = "wstest",
    Description = "description")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AsmxService : WebService
{
    [WebMethod]
    public string GetNumber(string name)
    {
        return Repository.GetNumber(name);
    }
}

#2


You need to look at the network traffic between the client and service to see what's going on. Alternatively, turn on WCF tracing on the service, possibly including message tracing. You should be able to see what's going on, in great detail.

您需要查看客户端和服务之间的网络流量,以查看正在发生的情况。或者,在服务上启用WCF跟踪,可能包括消息跟踪。您应该能够非常详细地了解正在发生的事情。