开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜