简体   繁体   中英

How to setup WCF service content type

After resolving the trouble with [KnownType] for class transporting : Providing array or list of class objects via WCF

I'm getting this when try to generate protocol with 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>

So I guess I must to set up application type to

application / soap + xml; charset = utf-8

but yet I can't understand how to make it.

here is how I'm creating current WCF host:

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);

in order to publish metadata you have to add a Metadata Exchange endpoint

/// 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");

除了添加ServiceMetadataBehavior之外,还必须添加元数据交换端点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM