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);
Related
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
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.
I created a REST GetTime Service in WCF and the service returns JSON as the response message. Also the WebMessageBodyStyle is set to wrapped so it would have an ID associated with that data it returns. But when I use Fiddler to test my service the response string is:
{"GetTimeResult":"2010614104013"}
As the response above the ID of the string is GetTimeResult, I'm wondering is there any way on changing that bit of test to timestamp. So it looks like this:
{"timestamp":"2010614104013"}
Cheers.
If you are using the DataContract/DataMember attributes in your code, you add a name (as well as some other named parameters).
[DataMember(Name = "timestamp")]
public string GetTimeResult
As pointed out in this article, suppose you are not using a data member explicitly in a data contract and want to return, say, a timestamp as a simple string for the response. Just use the annotation [return: MessageParameter(Name = "timestamp")] with your operation contract method:
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/timestamps", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
[return: MessageParameter(Name = "timestamp")]
string GetStringTimestamp();