简体   繁体   中英

Strange exception on WCF endpoint launch

I am getting the following exception and don't have much clue about what and how it should be fixed:

The operation 'ShowData' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

My code:

[ServiceContract(SessionMode=SessionMode.NotAllowed)] 
public interface IHelper 
{
  [WebGet(UriTemplate = "/cgi/manager.exe?GetData={data}")]
  [OperationContract]
  Message ShowData(int data);
}

public class Helper : IHelper 
{
  public Message ShowData(int data)
  {
    var result = new StringBuilder(...);

    foreach (...)
    {
      result.AppendFormat(...);
    }

    result.AppendLine(...);

    return WebOperationContext.Current.CreateTextResponse(result.ToString(), "text/xml", Encoding.ASCII);
  } 

I guess it says that I can't intermix Message with int ? What is the correct way to rely on parsing the request than?

You're getting the error because you're returning the WCF Message type. This means you'll either have to remove the data parameter from the inputs, or also make it a Message type instead of an int .

The Message class is a fundamental piece of the WCF infrastructure. It's documented here: http://msdn.microsoft.com/en-us/library/ms734675.aspx

It's better to define your own data-contract type rather than use Message .

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