C# 为什么将WCF服务设置为SOAP

C# 为什么将WCF服务设置为SOAP,c#,rest,web-services,wcf,soap,C#,Rest,Web Services,Wcf,Soap,我已经创建了上面提到的WCF服务,当使用MicrosoftWCF测试客户端测试它并尝试调用其中一个方法时,响应是“error400badrequest”。 另外,服务的类型显示为SOAP(请查看图片)为什么?这是WCF的默认值还是什么 服务合同: [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); [OperationContra

我已经创建了上面提到的WCF服务,当使用MicrosoftWCF测试客户端测试它并尝试调用其中一个方法时,响应是“error400badrequest”。 另外,服务的类型显示为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();



}
[服务合同]
公共接口IService1
{
[经营合同]
字符串GetData(int值);
[经营合同]
CompositeType GetDataUsingDataContract(CompositeType composite);
[经营合同]
字符串GetPatientNameByID(字符串ID);
[经营合同]
PatientsEnt getClass();
[经营合同]
[WebInvoke(UriTemplate=“AddNewBank”,Method=“POST”,
ResponseFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.Wrapped,RequestFormat=WebMessageFormat.Json)]
bool AddNewBank(bankssent银行);
[经营合同]
List GetBanksList();
//TODO:在此处添加服务操作
[经营合同]
[WebGet(UriTemplate=“ValidateRel/RelationNumber={RelationNumber}/CallID={CallID}”,ResponseFormat=WebMessageFormat.Json)]
string ValidateRel(字符串关系号,字符串CallID);
[经营合同]
[WebInvoke(Method=“POST”)]
字符串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";
    }
public bool AddNewBank(BanksEnt ent)
{
尝试
{
返回银行地址新银行(ent);
}
捕获(例外)
{
投掷;
}
}
公共列表GetBanksList()
{
尝试
{
返回BanksBiz.GetBanksList();
}
捕获(例外)
{
//AppendAllText(“log.txt”,例如Message);
抛出;//ex;
}
}
公共字符串ValidateRel(字符串关系号,字符串CallID)
{
回复“你好”;
}
公共病人信息获取类()
{
返回null;
}
公共字符串testSer()
{
返回“测试1服务”;
}
客户端中的端点配置

 <?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中有两种主要的SOAP Web服务绑定协议:

  • BasicHttpBinding适用于SOAP 1.1
  • 对于SOAP 1.2和WS-Addressing规范,WsHttpBinding
您必须注意到的主要区别是安全性方面,默认情况下,BasicHttpBinding以纯文本发送数据,而WsHttpBinding以加密和安全的方式发送数据

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


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

如何配置端点,您是否设置了正确的绑定和行为?请检查更新的问题。看起来您指示它充当soap服务,那么您为什么希望它充当非soap服务?您需要一个具有WebHttpBehavior的ServiceEndpoint。请阅读。考虑到关于WCF的大量问题,您可能会考虑首先遵循一些基本教程来掌握端点、绑定和合同背后的思想。考虑不要将端点地址作为一个步骤来保护Web服务免受DoS攻击。