【问题标题】:WCF service as stateless service in Service fabricWCF 服务作为 Service Fabric 中的无状态服务
【发布时间】:2018-04-09 04:56:56
【问题描述】:

我正在使用 BasicHttpBinding 在 WCF 服务中创建 SOAP 服务(ASMX 服务)。同实现here

编写接口如下

[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
        }
    }

Service Fabric 运行后,无状态服务正常运行。

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

【问题讨论】:

  • 这是一个 WCF 服务示例:github.com/loekd/ServiceFabric.WcfCalc
  • "...SOAP 服务(ASMX 服务)到 WCF..." - 好吧,ASMX 服务既不是 SOAP 服务,也不是使用 WCF。 ASMX 服务早于 WCF 和 SOAP
  • @LoekD,我通过将您的代码作为参考来实施我的服务。感谢那。但是,当我尝试运行我的 ATP 来测试特定的 API 时,那些 ATP 失败了,结果给了我错误的请求。我是 SOAP API 的新手。

标签: c# web-services wcf soap azure-service-fabric


【解决方案1】:

它不会像那样工作。 SOAP 需要将客户端请求(实际上是它们的主体)封装到 XML 中。

在浏览器中输入地址不会创建任何 XML,而是发送一个普通的请求

所以,

  1. 您可以使用其他东西来发送 SOAP 请求(例如,WCF 客户端,您必须使用 C# 编写,或者使用第三方产品,如 SoapUI
  2. 或者你放弃SOAP需求,使用WCF创建一个REST服务,不需要XML body,可以通过浏览器调用

如果你决定使用#2,你必须在你的 svc 文件中添加这个属性

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

【讨论】:

    猜你喜欢
    • 2016-11-16
    • 2017-03-07
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 2019-09-10
    • 2016-11-23
    • 2017-06-26
    相关资源
    最近更新 更多