繁体   English   中英

为什么 WCF 服务被设置为 SOAP

[英]Why WCF service is set as SOAP

在此处输入图片说明

我在使用 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();



}

服务1.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>

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

  • SOAP 1.1 的BasicHttpBinding
  • 以及用于 SOAP 1.2 和 WS-Addressing 规范的WsHttpBinding

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

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

WCF Web 编程模型允许开发人员通过 HTTP 请求公开 WCF Web 服务,这些 HTTP 请求使用“plain old XML”(POX) 样式消息而不是基于 SOAP 的消息。 对于使用 HTTP 请求与服务通信的客户端,服务的端点必须配置有附加到它的 。

暂无
暂无

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

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