我在 WCF 中有两个单独的消息合同:
[MessageContract(WrapperName = "GetFooRequest", WrapperNamespace = "http://whatever.services.schema")]
public class GetFooRequest
{
[MessageHeader]
public int ResponseType { get; set; }
[MessageBodyMember(Order = 1)]
public string FirstName { get; set; }
[MessageBodyMember(Order = 1)]
public string LastName { get; set; }
}
[MessageContract(WrapperName = "GetBarRequest", WrapperNamespace = "http://whatever.services.schema")]
public class GetBarRequest
{
[MessageHeader]
public int ResponseType { get; set; }
[MessageBodyMember(Order = 1)]
public string FirstName { get; set; }
[MessageBodyMember(Order = 1)]
public string LastName { get; set; }
}
这很好用,但是一旦我在 GetBarRequest 上更改 MessageHeader 的类型,该服务就不再起作用:
[MessageHeader]
public string ResponseType { get; set; }
现在我在 GetFooRequest 和 GetBarRequest 中都有一个名为 ResponseType 的 MessageHeader,但它们有不同的类型。该服务不再起作用。为什么我不能在两个完全不同的消息合约上拥有同名/不同类型的 MessageHeader?
我得到的错误非常神秘:
Error: Cannot obtain Metadata from http://localhost:42575/Services/Test/TestService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:42575/Services/Test/TestService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:42575/Services/Test/TestService.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:42575/Services/Test/TestService.svc. The client and service bindings may be mismatched. The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error URI: http://localhost:42575/Services/Test/TestService.svc There was an error downloading 'http://localhost:42575/Services/Test/TestService.svc'. The underlying connection was closed: The connection was closed unexpectedly.