WCF Service Proxy throws exception when more than one parameter is used in [OperationContract] method

后端 未结 4 1049
忘了有多久
忘了有多久 2020-12-10 06:12

I have a WebServiceHost that is being used to host some web services in a console app. I added a service reference to it in my client app and create the proxy like so:

相关标签:
4条回答
  • 2020-12-10 06:27

    Two solutions I found:

    If you can remove <webHttp/>

    From

    <behaviors>
      <endpointBehaviors>
        <behavior>
          <!--<webHttp/>-->
        </behavior>
      </endpointBehaviors>
    </behaviors>
    

    If you cannot, I had to add the attribute

    [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    

    Above the Operation Contact Method

    0 讨论(0)
  • 2020-12-10 06:33

    Try changing the hosting environment of your service within Visual Studio.
    Change it from Use local IIS to 'Use Visual Studio Development Server'.

    Apparently there is a different behaviour depending the hosting environment.

    0 讨论(0)
  • 2020-12-10 06:37

    I have another scenario for this issue, even if I added [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)] on the Operation Contact Method, it still doesn't work, I found this post is resolve my problem. http://www.codemeit.com/wcf/wcf-restful-pox-json-and-soap-coexist.html

    What we need to do is simply locate the file “reference.cs” generated after adding service reference. Search keyword: “public interface ITestService” within the client project, you will find the generated service contract, add [System.ServiceModel.Web.WebGet] on top of the OperationContract.

    So I had had added [System.ServiceModel.Web.WebGet] on the top of OprationContract on the proxy class of client side, it works.

    0 讨论(0)
  • 2020-12-10 06:42

    It seems you have created Proxy code using Add Service Reference dialog in VS. VS ASR dialog doesn't support WCF REST fully, so, the proxy code is missing [WebInvoke] attribute. Can you try adding [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)] attribute on operations in client proxy?

    0 讨论(0)
提交回复
热议问题