gpt4 book ai didi

c# - 具有相同返回类型和名称的 MessageBodyMembers 导致异常 - 元素已导出

转载 作者:太空狗 更新时间:2023-10-29 23:32:35 26 4
gpt4 key购买 nike

我正在遵循一种模式,该模式具有用于 WCF 服务的请求和响应的对象。我有多个具有相同返回类型和名称的请求对象。任何帮助将不胜感激。

我收到以下异常:

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IService ----> System.InvalidOperationException: The Service.ServiceContract.IService.RetrieveUsers operation references a message element [http://tempuri.org/:WeekEndingId] that has already been exported from the Service.ServiceContract.IService.RetrieveDepartments operation. You can change the name of one of the operations by changing the method name or using the Name property of OperationContractAttribute. Alternatively, you can control the element name in greater detail using the MessageContract programming model.

编辑:我在属性上使用了 Name 属性来赋予它们唯一的名称,这确实解决了问题,但我们需要为所有请求使用名称“WeekEndingId”。我想尝试找到解决此问题的方法,同时仍然使用相同的属性名称。

下面列出了导致问题的类:

检索部门请求:

[MessageContract(WrapperName = "RetrieveDepartmentsRequest", WrapperNamespace = "http://Service.V1")]
public class RetrieveDepartmentsRequest
{
[MessageBodyMember(Order = 0)]
public int WeekEndingId { get; set; }

[MessageBodyMember(Order = 1)]
public string UserId { get; set; }

[MessageBodyMember(Order = 2)]
public string MachineName { get; set; }
}

检索用户请求:

[MessageContract(WrapperName = "RetrieveUsersRequest", WrapperNamespace = "http://Service.V1")]
public class RetrieveUsersRequest
{
[MessageBodyMember(Order = 0)]
public int WeekEndingId { get; set; }

[MessageBodyMember(Order = 1)]
public string UserId { get; set; }

[MessageBodyMember(Order = 2)]
public string MachineName { get; set; }
}

I服务:

[OperationContract]
[FaultContract(typeof(ServiceFault))]
RetrieveDepartmentsResponse RetrieveDepartments(RetrieveDepartmentsRequest request);

[OperationContract]
[FaultContract(typeof(ServiceFault))]
RetrieveUsersResponse RetrieveUsers(RetrieveUsersRequest request);

最佳答案

我认为这是一种类型冲突。在那里面:WeekEndingId 在 RetrieveDepartmentsRequest 中是一个整数,在 RetrieveUsersRequest 中是一个小数。使用 MessageBodyMember 的 Name 属性来解决冲突。或者只需更改 RetrieveUsersRequest 中的属性名称即可。

或者更好:WeekEndingId 不应该总是一个 int 吗?

关于c# - 具有相同返回类型和名称的 MessageBodyMembers 导致异常 - 元素已导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15120613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com