【问题标题】:Why WCF service is set as SOAP为什么 WCF 服务设置为 SOAP
【发布时间】:2018-07-22 14:41:52
【问题描述】:

我在使用 Microsoft WCF 测试客户端对其进行测试并尝试调用其中一种方法时创建了上述 WCF 服务,响应为“ERROR 400 Bad Request”。 此外,服务的类型显示为 SOAP(检查图像)为什么?这是 WCF 的默认设置还是什么?

服务合同:

  [ServiceContract]
public interface IService1
{

    [OperationContract]
    string GetData(int value);

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);

    [OperationContract]
    string GetPatientNameByID(string ID);

    [OperationContract]
    PatientsEnt getClass();

    [OperationContract]
    [WebInvoke(UriTemplate ="AddNewBank",Method ="POST",
       ResponseFormat = WebMessageFormat.Json,
        BodyStyle =WebMessageBodyStyle.Wrapped,RequestFormat =WebMessageFormat.Json)]
    bool AddNewBank(BanksEnt bank);

    [OperationContract]
    List<BanksEnt> GetBanksList();
    // TODO: Add your service operations here   

    [OperationContract]
    [WebGet(UriTemplate = "ValidateRel/RelationNumber={RelationNumber}/CallID={CallID}", ResponseFormat = WebMessageFormat.Json)]
    string ValidateRel(string RelationNumber, string CallID);

    [OperationContract]
    [WebInvoke(Method = "POST")]
    string testSer();



}

Service1.svc

   public bool AddNewBank(BanksEnt ent)
    {
        try
        {
            return     BanksBiz.AddNewBank(ent);              

        }
        catch (Exception)
        {

            throw;
        }
    }
    public List<BanksEnt> GetBanksList()
    {
        try
        {
            return BanksBiz.GetBanksList();


        }
        catch (Exception )
        {
            // File.AppendAllText("log.txt",ex.Message);
            throw;// ex;
        }

    }

    public string ValidateRel(string RelationNumber, string CallID)
    {
        return "hello";
    }

    public PatientsEnt getClass()
    {
        return null;
    }


    public string testSer()
    {
        return "test-1 service";
    }

客户端中的端点配置

 <?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="soapService" sendTimeout="00:05:00" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://www.example.net/cms/Service1.svc/soap"
                binding="basicHttpBinding" bindingConfiguration="soapService"
                contract="IService1" name="soapService" />
        </client>
    </system.serviceModel>
</configuration>

【问题讨论】:

  • 端点是如何配置的,你设置正确的绑定和行为了吗?
  • 请查看更新后的问题
  • 您似乎指示它充当肥皂服务,那么您为什么希望它充当非肥皂服务?
  • 您需要有一个带有 WebHttpBehavior 的 ServiceEndpoint。请阅读the docs。鉴于您对 wcf 有很多问题,您可能会考虑先学习一些基本教程,以掌握端点、绑定和契约背后的概念。
  • 考虑不要透露您的端点地址,以保护 Web 服务免受 DoS 攻击

标签: c# rest web-services wcf soap


【解决方案1】:

因为您的端点使用的是 SOAP 绑定协议“basicHttpBinding”。 WCF 中有 2 个主要的 SOAP Web 服务绑定协议:

  • BasicHttpBinding 用于 SOAP 1.1
  • WsHttpBinding 用于 SOAP 1.2 和 WS-Addressing 规范。

您必须注意到的主要区别是安全方面,默认情况下,BasicHttpBinding 以纯文本形式发送数据,而 WsHttpBinding 以加密和安全的方式发送数据。

否则对于 REST 服务,这是 MSDN 备注

WCF Web 编程模型允许开发人员通过 HTTP 请求公开 WCF Web 服务,该请求使用“普通旧 XML”(POX) 样式消息传递而不是基于 SOAP 的消息传递。为了让客户端使用 HTTP 请求与服务进行通信,服务的端点必须配置有附加到它的 。

【讨论】:

    猜你喜欢
    • 2019-04-15
    • 2011-12-30
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 2014-06-02
    • 2023-03-19
    • 2013-06-13
    • 2013-08-23
    相关资源
    最近更新 更多