Конечные точки REST/SOAP для службы WCF

На этот пост уже есть очень wcf хороший ответ от «Вики сообщества», и restful-architecture я также рекомендую посмотреть restful веб-блог Рика Страла, там wcf много хороших постов о WCF wcf-service Rest, таких как this.

Я использовал wcf-service оба, чтобы получить такую wcf ​​услугу MyService ... Затем wcf-service я могу использовать REST-интерфейс restful-web-services из jQuery или SOAP из Java.

Это restful-web-services из моего Web.Config:


 
  
   
   
   
  
 
 
  
   
    
    
   
  
  
   
    
   
  
 

И это rest-api мой служебный класс (.svc-codebehind, интерфейсы restful-architecture не требуются):

    ///  MyService documentation here ;) 
[ServiceContract(Name = "MyService", Namespace = "http://myservice/", SessionMode = SessionMode.NotAllowed)]
//[ServiceKnownType(typeof (IList))]
[ServiceBehavior(Name = "MyService", Namespace = "http://myservice/")]
public class MyService
{
    [OperationContract(Name = "MyResource1")]
    [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "MyXmlResource/{key}")]
    public string MyResource1(string key)
    {
        return "Test: " + key;
    }

    [OperationContract(Name = "MyResource2")]
    [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "MyJsonResource/{key}")]
    public string MyResource2(string key)
    {
        return "Test: " + key;
    }
}

На самом деле restful-architecture я использую только Json или wcf-service Xml, но они оба здесь для rest демонстрации. Это GET-запросы restful-web-services на получение данных. Для soap вставки данных я бы использовал restful-web-services метод с атрибутами:

[OperationContract(Name = "MyResourceSave")]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "MyJsonResource")]
public string MyResourceSave(string thing){
    //...

wcf

rest

soap

2022-09-21T03:04:27+00:00
Вопросы с похожей тематикой, как у вопроса:

Конечные точки REST/SOAP для службы WCF