Getting return type invalid error while trying to call WCF webservice 4.0

前端 未结 1 1673
独厮守ぢ
独厮守ぢ 2021-01-19 14:06

I am trying to write and call WCF web service, below are the details:

Web.config:



        
相关标签:
1条回答
  • 2021-01-19 14:30

    I believe mentioned error is quite self-explaining. According to the MSDN, using Message class has its own restrictions:

    You can use the Message class as an input parameter of an operation, the return value of an operation, or both. If Message is used anywhere in an operation, the following restrictions apply:

    • The operation cannot have any out or ref parameters.
    • There cannot be more than one input parameter. If the parameter is present, it must be either Message or a message contract type.
    • The return type must be either void, Message, or a message contract type.

    In case of your contract, the second restriction is violated. The easiest workaround is to create proper MessageContract:

    [MessageContract]
    public class RetrievePublishedDataInput
    {
      [MessageBodyMember] public string Pub;
      [MessageBodyMember] public int Number;
    }
    
    private Message RetrievePublishedData(RetrievePublishedDataInput input)
    {
        ....
    }
    
    0 讨论(0)
提交回复
热议问题