1

クラス転送の[KnownType]の問題を解決した後:WCFを介してクラスオブジェクトの配列またはリストを提供する

svcutilを使用してプロトコルを生成しようとすると、これが発生します。

Attempting to download metadata from 'http://localhost:8080/NEN_Server' using WS-Metadata Exchange or DIS
    CO.
    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    Error: Cannot obtain Metadata from http://localhost:8080/NEN_Server
    
    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, pleas
    e refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
    
    
    WS-Metadata Exchange Error
        URI: http://localhost:8080/NEN_Server
    
        Metadata contains insoluble link: "http://localhost:8080/NEN_Server".
    
        Content Type application / soap + xml; charset = utf-8 is not supported by http://localhost:8080/N
    EN_Server. This can be caused by mismatch of client and service bindings.
    
        The remote server returned an error: (415) Cannot process the message because the content type 'applica
    tion / soap + xml; charset = utf-8 'was not the expected type' text / xml; charset = utf-8 '..
    
    
    HTTP GET Error
        URI: http://localhost:8080/NEN_Server
    
        There was an error loading "http://localhost:8080/NEN_Server".
    
        The request failed with the error message:
    -
    <HTML> <HEAD> <STYLE Type="text/css"> # content {FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em; MARGIN-LEFT: 30px} BOD
    Y {MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR: # 000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white} P {MARG
    IN-TOP: 0px; MARGIN-BOTTOM: 12px; COLOR: # 000000; FONT-FAMILY: Verdana} PRE {BORDER-RIGHT: # f0f0e0 1px soli
    d; PADDING-RIGHT: 5px; BORDER-TOP: # f0f0e0 1px solid; MARGIN-TOP:-5px; PADDING-LEFT: 5px; FONT-SIZE: 1.2
    em; PADDING-BOTTOM: 5px; BORDER-LEFT: # f0f0e0 1px solid; PADDING-TOP: 5px; BORDER-BOTTOM: # f0f0e0 1px sol
    id; FONT-FAMILY: Courier New; BACKGROUND-COLOR: # e5e5cc}. heading1 {MARGIN-TOP: 0px; PADDING-LEFT: 15px; FO
    NT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT:-30px; WIDTH: 1
    00%; COLOR: # ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-COLOR: # 003366}. Intro {MARGIN-LEFT
    :-15px} </ STYLE> <TITLE> Service </ TITLE> </ HEAD> <BODY> <DIV id="content"> <P class="heading1"> Service </ P> <BR/>
    <P Class="intro"> The server was unable to process the request due to an internal error. For more informa
    tion about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute
     or from the <serviceDebug> configuration behavior) on the server in order to send the exception informat
    ion back to the client, or turn on tracing as per the Microsoft. NET Framework SDK documentation and insp
    ect the server trace logs. </ P> </ DIV> </ BODY> </ HTML>

だから私はアプリケーションタイプを設定する必要があると思います

application / soap + xml; charset = utf-8

しかし、それでも私はそれを作る方法を理解することができません。

現在のWCFホストを作成する方法は次のとおりです。

private void createHost() {
    /// Create the ServiceHost.
    using (ServiceHost host = new ServiceHost(typeof(NEN), baseAddress)) {
        /// Enable metadata publishing.
        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
        host.Description.Behaviors.Add(smb);
4

2 に答える 2

2

メタデータを公開するには、Metadata Exchange エンドポイントを追加する必要があります

/// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(NEN), baseAddress)) {
    /// Enable metadata publishing.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    host.Description.Behaviors.Add(smb);

// Add MEX endpoint
  host.AddServiceEndpoint(
  ServiceMetadataBehavior.MexContractName,
  MetadataExchangeBindings.CreateMexHttpBinding(),
  "mex");
于 2012-08-22T05:29:07.183 に答える
1

ServiceMetadataBehavior を追加するだけでなく、メタデータ交換エンドポイントも追加する必要があります。

于 2012-08-22T06:10:21.347 に答える