簡體   English   中英

WCF中的MessageHeader問題

[英]MessageHeader Issue in WCF

我在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.

消息協定在wsdl上顯示為原始類型,因此GetBarRequestGetFooRequest看起來如下

WCF不按名稱和類型驗證模式,僅驗證名稱,因此類型更改名稱相同,發生以下錯誤

**操作引用已從**操作導出的消息元素[ http://tempuri.org/:ResponseType] 您可以通過更改方法名稱或使用OperationContractAttribute的Name屬性來更改其中一個操作的名稱。 或者,您可以使用MessageContract編程模型更詳細地控制元素名稱。

[MessageHeader(Name = "TextResponseType")]
public string ResponseType { get; set; }  - Name property resolve the issue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM