繁体   English   中英

WCF服务作为Service Fabric中的无状态服务

[英]WCF service as stateless service in Service fabric

我正在使用BasicHttpBinding将SOAP服务(ASMX服务)创建到WCF服务中。 此处实施相同

编写界面如下

[ServiceContract]
public interface IExample
    {
    [OperationContract]
    [WebMethod]
    Task<XmlElement> GetDetails ();

    [OperationContract]
    [WebInvoke(Method = "Get", UriTemplate = "/GetExample")]
    Task<string> GetExample (string guid);
    }

接口的实现:

        public class ImplementInteface: IExample{
        public ImplementInterface(){}

        public Task<XmleElement> GetDetails(){
            //Implementation of GetDetails function
        }

        public Task<string> GetExample(string guid){
            //Implementation of GetExampl function
        }
    }

运行服务结构后,无状态服务将正常运行。

我有旧代码(asmx文件),其中已经定义了相同的结构,并且具有相同的ATP。 遗留API公开的网址,我不想弄乱它。 我想将新的SOAP API公开给相同的URL。 但是,当我尝试从无状态服务调用新的SOAP API时,它向我发出错误的错误请求 有什么方法可以将这些api创建到服务结构中的无状态服务中吗?

那样就行不通了。 SOAP需要将客户端请求(实际上是它们的主体)封装为XML。

在浏览器中输入地址不会创建任何XML,但会发送简单请求

所以,

  1. 您可以使用其他方式发送SOAP请求(例如,必须使用C#编写的WCF客户端 ,或类似SoapUI的第三方产品)
  2. 或者,您放弃SOAP要求并使用WCF创建REST服务,该服务不需要XML主体,可以通过浏览器调用

如果决定使用#2,则必须在svc文件中添加此属性

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM