I have a wcf service, which I made restfull, but editing the intereface and the webconfig.
In the interface, I have the following:
[ServiceContract]
public interface ITsmApi
{
[OperationContract]
[WebInvoke(UriTemplate = "/GetOrganizationNo", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Xml, Method = "POST")]
string GetOrganizationNo(CustomerNoInput input);
}
I would like if it is possible that I call the webservice function in this manner:
http://foo.example/api/v1/accounts/3
I would like that my URL link to the functions don't look like this:
http://servername.com/MyApi/MyApi.svc/AddPerson - meaning I would like to not have the SVC extension. Is that possible at all?
I have suspicion that I have to use service contract namespace, but I can't find what the procedure is?
Related
My first WEB servicee usinf Visual Studio 2013 Express WEB, and I can't make it restfull. basically want to return a json string and got the following service definition;
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json, UriTemplate = "Name")]
string Name();
Implementation of Name just returns a string which is shown when I Invoke the function through the WCF Test Client, but calling the http://localhost:58116/Service1.svc/Name returns nothing. I was expecting a json representation of the Name.
Any idea's?
I want to wrap each result from one Wcf service in my application in something like
public class OperationResult{
public string Status;
public string Data;
}
even if my contract looks like
[ServiceContract]
internal interface ITest
{
[OperationContract,
WebGet(
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
MyDc EchoDc(MyDc input);
}
From what I've read the potential extensibility points are IServiceBehavior, IEndpointBehavior, IContractBehavior, IOperationBehavior.
Any thoughts where I can hook my wrapping magic ?
Look # my answer here:
How to customize the process employed by WCF when serializing contract method arguments?
There it is mentioned how you can replace an object of one type to another type while it is being returned.
I think thats not possible via extensionpoints on the WCF framework because what you watn to do is to change your contract.
The contract is a c# interface which is used by your client.
You have to write an own proxy class for use by your client where you can map the operation results to whatever you like:
class ServiceProxy : ClientBase<YourServiceInterface>
{
public OperationResult EchoDc(MyDs input)
{
MyDc result = Channel.EchoDc(input);
return new OperationResult( ... // map your operation result here))
}
}
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();
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.