2

我知道我可以通过分配 DTO 来管理 REST-ful 接口操作的路由

[Route("/widgets", "GET, POST")]
[DataContract()]
public class GetWidgetsRequest
{
    [DataMember]
    public string OutletCode { get; set; }
    [DataMember]
    public IList<Specification> WidgetsCaptured { get; set; }
}

但是我已经搜索并尝试过尝试影响给定 SOAP 操作的端点的默认 /soap11 附件,但均未成功。

**POST /soap11 HTTP/1.1**
Host: localhost    
Content-Type: text/xml; charset=utf-8
Content-Length: nnn
SOAPAction: GetItemsRequest

问题中的一个更广泛的问题是,我有哪些选择以及如何配置不同的端点设置?

谢谢!

4

2 回答 2

0

For a different SOAP path, eg ~/services, you can add your own servicestack plugin , that returns your own servicestack soap handler.

public class MySoapFeature : IPlugin 
{
    private static IHttpHandler GetHandlerForPathParts(string[] pathParts)
    {
        string str2 = string.Intern(pathParts[0].ToLower());
        if (pathParts.Length != 1) return null;
        if (str2 == "services")
        {
            return new MySoapHttpHandler();
        }

        return null;
    }

    public IHttpHandler ProcessRequest(string httpMethod, string pathInfo, string filePath)
    {
        char[] chrArray = new char[] { '/' };
        string[] strArrays = pathInfo.TrimStart(chrArray).Split(new char[] { '/' });
        if ((int)strArrays.Length == 0)
        {
            return null;
        }

        return MySoapFeature.GetHandlerForPathParts(strArrays);
    }

    public void Register(IAppHost appHost)
    {
        appHost.CatchAllHandlers.Add(this.ProcessRequest);
    }
}

Then implement this handler based on Soap11Handler or Soap12Handler

    public class MySoapHttpHandler : Soap11Handler, IHttpHandler
{
    public MySoapHttpHandler()
        : base((EndpointAttributes)((long)32768))
    {
    }

    public new void ProcessRequest(HttpContext context)
    {
        if (context.Request.HttpMethod == "GET")
        {
            (new Soap11WsdlMetadataHandler()).Execute(context);
            return;
        }

        Message message = base.Send(null);
        context.Response.ContentType = base.GetSoapContentType(context.Request.ContentType);
        using (XmlWriter xmlWriter = XmlWriter.Create(context.Response.OutputStream))
        {
            message.WriteMessage(xmlWriter);
        }
    }


    public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
    {
        if (httpReq.HttpMethod == "GET")
        {
            (new Soap11WsdlMetadataHandler()).Execute(httpReq, httpRes);
            return;
        }

        Message message = base.Send(null, httpReq, httpRes);
        httpRes.ContentType = base.GetSoapContentType(httpReq.ContentType);
        using (XmlWriter xmlWriter = XmlWriter.Create(httpRes.OutputStream))
        {
            message.WriteMessage(xmlWriter);
        }
    }

Then register your plugin in the servicestack apphost Configure()

Plugins.Add(new MySoapFeature());

Then create your Dto classes for the request and response. Have "Response" added to the response dto class name. Do NOT put a Route attribute on the request Dto, as it gets routed by the Soap method name in the Xml.

[DataContract(Namespace = "http://mynamespace/schemas/blah/1.0")]
public class MySoapMethod
{}


DataContract(Namespace = "http://mynamespace/schemas/blah/1.0")]
public class MySoapMethodResponse
{
     [DataMember]
    public string SomeProperty { get; set; }
}

Then have a Service to implement the Soap Dto's

public class SOAPService : Service
{
    public MySoapMethodResponse Post(MySoapMethod request)
    {
        var response = new MySoapMethodResponse();
        response.SomeProperty = "blah";
        return response;
    }
}
于 2014-01-09T18:55:20.737 回答
0

请阅读SOAP 支持文档,了解在 ServiceStack 中使用 SOAP 的指南和限制。

于 2013-11-14T21:54:55.437 回答