Swagger allows setting the parameter type but with SwaggerWcf I can't edit this file, it's generated. It's set to body by default, but I need it to be path.
One might think SwaggerWcfParameterAttribute would allow setting this. But it only allows Description and Required.
How can it be set specifically?
Did you try using the format in the sample service?
https://github.com/abelsilva/swaggerwcf/blob/master/src/SwaggerWcf.Test.Service/IStore.cs#L48
[SwaggerWcfPath("Get book author", "Retrieve the author of a book using the book id")]
[WebGet(UriTemplate = "/books/{id}/author", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
Author ReadBookAuthor(string id);
The parameter id from the path will be passed to the function
Related
Actual error on on client side while applying client behavior :
Operation 'GetCurrentStreamPositionByStreamId' of contract
'IVideoService' specifies multiple request body parameters to be
serialized without any wrapper elements. At most one body parameter
can be serialized without wrapper elements. Either remove the extra
body parameters or set the BodyStyle property on the
WebGetAttribute/WebInvokeAttribute to Wrapped.
Specify uritemplate in webinvoke attribute over the method as:
[OperationContract]
[WebInvoke(
Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "getcurrenttime/{managerid}/{streamid}")]
DateTime GetRecordedVideoCurrentTime(string managerid,string streamid);
I am getting a "Method not allowed." error from my WCF service when invoking a GET operation. I know why this is happening but can't understand why it is not allowed. I guess I might be doing something wrong. I am trying to use the same UriTemplate (attribute) structure for GET and POST. I am following a standard REST service convention:
GET - /api/v1/{entityType} - to get a list of {entityType} e.g. /api/v1/cars
POST - /api/v1/{entityType} - to insert an entity e.g /api/v1/car
[OperationContract]
[WebGet(BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "api/v1/{entityType}?skip={skip}&take={take}")]
List<Entity> GetEntityList(string entityType, int skip, int take);
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "api/v1/{entityType}")]
Entity InsertEntity(string entityType, Entity entity);
I understand that my UriTemplates are the same but why is this not allowed? Doesn't the server detect what operation I am trying to perform?
I made my method with post like this:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
List<Human> GetHuman(UserEnteredName humanName);
The UserEnteredName class has just one property - string.
And it works. But, I need to make it to be get, not post.
I tried with this:
[WebInvoke(Method= "GET", UriTemplate = "GetHuman?username={John}",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
But it doesn't work. What do I need to change?
According to your UriTemplate, your method would have to look something like
Human GetHuman(string John)
I suspect you are mistakenly putting a possible parameter value in your UriTemplate. Try something like
[WebInvoke(Method= "GET", UriTemplate = "GetHuman?username={userName}",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
Human GetHuman(string userName)
Also, for GET, you can use the WebGetAttribute, which is slightly cleaner.
I would change your method to take a string parameter and construct the UserEnteredName instance in the method body. It may be possible to use your UserEnteredName type as a parameter if it uses the TypeConverterAttribute, but I have never done this, so I can't say how easy (or not) it is. See the WCF Web HTTP Programming Model Overview, specifically the UriTemplate Query String Parameters and URLs section.
I have a big problem.
I created a WCF service.My POST declaration looks like this:
[OperationContract]
[WebInvoke(UriTemplate = "json/put",
Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
string PutData(string jsonText);
I was expecting that when I'm sending data (I'm using fiddler2 to test it) that it will automaticly "put" into the jsonText variable.
The service works, but there is no data :(.
Can anybody help? The whole project
WCF expects the JSON payload to be deserialized into a type. Try creating a class that is shaped like your JSON payload and use that as the parameter type.
When using the following interface to talk to PHP from .NET, .NET builds the request body XML with parameter names barcode and branch. The parameter names should be Barcode and Branch. Yes, the PHP server is case sensitive.
Am I forced to capitalise my parameter names? or can I specify names using attributes?
Many Thanks
Neil
[ServiceContract]
public interface IStockEnquiryService
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "")]
Branches GetStockInfo(string barcode, string branch);
}
Try applying the MessageParameterattribute to the method arguments and specify the right case in its Name property.