我是 WCF 的新手。我有一个示例 WCF 服务器和一个使用该服务的客户端。我有一个名为 getEmployer4 的 OperationContract,它接受一个 EmployerRequestBO 并返回一个 EmployerResponseBO,这两种类型都被装饰为 MessageContract
public EmployerResponseBO getEmployer4(EmployerRequestBO rqst)
{
return new EmployerResponseBO
{ CompanyName = "Apple", CompanyAddress = "US" };
}
我的 EmployerRequestBO 看起来像:
[MessageContract(IsWrapped = true, WrapperName = "EmployerRequest", WrapperNamespace ="http://mycompany.com/services")]
public class EmployerRequestBO
{
[MessageHeader(Namespace = "http://mycompany.com/services")]
public string LicenseKey
{
get; set;
}
private int _regID;
[MessageBodyMember(Order = 1, Name = "CompanyRegistrationID", Namespace = "http://mycompany.com/services")]
public int RegistrationID
{
get
{
return _regID;
}
set
{
_regID = value;
}
}
问题是,当我尝试使用以下代码调用客户端中的操作时:
ServiceReference_EmployerService.EmployerClient client = new ServiceReference_EmployerService.EmployerClient("BasicHttpBinding_IEmployer");
ServiceReference_EmployerService.EmployerRequestBO request = new ServiceReference_EmployerService.EmployerRequestBO("ABC123", 123);
ServiceReference_EmployerService.EmployerResponseBO response= client.getEmployer4(request);
getEmployer4 不需要 EmployerRequestBO 参数,错误如下所示
没有给出与“EmployerClient.GetEmployer4(string, ref int, out string)”的所需形式参数“CompanyRegistrationID”相对应的参数。
谁能解释为什么它要求原始类型而不是 MessageContract 类型?谢谢!