Issue with Swagger Wcf Generated Example Code

1.4k Views Asked by At

I'm trying to use https://github.com/abelsilva/swaggerwcf

But having issues using it with our WCF methods

An example is something like this:

public ETemplate GetETemplate(int eTemplateId)

We exposed the svc via a webHttpBinding with enableWebScript set in the behavior

When we normally use REST to access it from jQuery we would use this in the Post

{"eTemplateId": "26000"}

But from the example data generated from SwaggerWcf we are getting simply an integer passed in the POST like this

26000

Below is how I've decorated the method on the Interface, i think this is correct because the WebMessageBodyStyle is correctly set to Wrapped and not Bare.

Am I missing something simple?

   [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST",
            RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
1

There are 1 best solutions below

0
Juan Acosta On

Could you please give more information about your issue. Something seems off. I don't think the Request Format will create errors in swagger implementation. Try to download the project swaggerator. https://github.com/superstator/Swaggeratr That's the initial version of SwaggerWCF were the branch converts in SwaggerWCF. You will find them some useful examples of the initial integration. Generally speaking it won't change much.

In Swaggerator you will find definitions like this one for post methods.

[Tag("InternalUse")]
        [OperationSummary("Does stuff.")]
        [OperationNotes("I mean, it does some really interesting stuff. Stuff like you wouldn't believe.")]
        [ResponseCode(400, "Four hundred error")]
        [ResponseCode(200, "OK")]
        [ResponseCode(205, "Some error")]
        [ResponseCode(404, "Not found")]
        [ResponseCode(401, "Something weird happened")]
        [ResponseCode(301, "Three O one Something weird happened")]
        [OperationContract]
        [WebInvoke(UriTemplate = "/data", Method = "POST", RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare)]
        CompositeType GetDataUsingDataContract(CompositeType composite);

Try to check that example implementation and please post more details about the issue you have. Otherwise, it is complicated to give more help.

I just create a fork. Because, I found some issues in the deploy. https://github.com/gabrielacosta/swaggerwcf If you download that branch. The code is working and maybe it can give a better perspective.