Good day.

I am here with a question that I can’t understand on my own.

Question: What is UriTemplate and what is it eaten with?

I analyzed specific examples. For example:

[ServiceContract(Namespace = "urn:example:services")] public interface ISomeWcf { [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetResult?client={client}&password={password}&messageId={messageId}")] string GetResultHttpGet(string client, string password, string messageId); } 

In this particular case, the UriTemplate sets a template by which we can access the GetResultHttpGet method through a REST request. Read MSDN, but did not understand.

Why specify Namespace = "urn: example: services"?

Can you tell me what to do with the UriTemplate ? It seems that I am wandering around with the answer, but I cannot formulate it.

thank

    1 answer 1

    UriTemplate defines a template by which it is determined whether an incoming request should be sent to the given Uri to be serviced by the GetResultHttpGet method, and also matches parts of the Uri to the method parameters.

    Suppose for this contract the base address

     http://hostname/SomeWcf/ 

    If an application (or directly by the browser) makes a GET request

     http://hostname/SomeWcf/GetResult?client=CLI&password=PWD&messageId=MSG 

    This will GetResultHttpGet service method. In this case, the parts of Uri will become the values ​​of the corresponding parameters:

     string GetResultHttpGet(string client, string password, string messageId) { //здесь части Uri станут значениями параметров: //client = "CLI"; //password = "PWD"; //messageId = "MSG"; ... } 

    If you deviate from the template, setting something else, for example

     http://hostname/SomeWcf/GetResult2?name=NAME или http://hostname/SomeWcf/GetResult3/Name/Foo 

    then the GetResultHttpGet method will not be called.

    As for the Namespace property of the ServiceContract attribute

     [ServiceContract(Namespace = "my.company.com")] 

    then it appears in the header soap-envelope

     <s:Envelope ...> <s:Header> ... <a:Action s:mustUnderstand="1" ...>my.company.com/ISomeWcf/GetResultHttpGet</a:Action> ... </s:Header> <s:Body ...> ... </s:Body> </s:Envelope> 

    If you do not specify it

     [ServiceContract] 

    then instead of my.company.com there will be a default value ( http://tempuri.org ).

    If the interface describing the contract is in the assembly referenced by both the client and the server, then in principle the Namespace can be anything. If the interface is described twice - in the client part and in the server part, or if you create a client for an existing service with a specific Namespace , then Namespace must match so that the client and server understand each other, otherwise the answer will be

     <s:Envelope ...> ... <s:Body> <s:Fault> ... <s:Reason> <s:Text xml:lang="en-US"> The message could not be processed because the action 'http://tempuri.org/ISomeWcf/GetResultHttpGet' is invalid or unrecognized. </s:Text> </s:Reason> </s:Fault> </s:Body> </s:Envelope>