如何从fiddler调用简单的wcf

时间:2016-11-14 11:22:15

标签: c# wcf

我有一个简单的wcf soap服务。在visual studio中运行它并在localhost上运行

enter image description here

尝试从fiddler访问GetData方法,但它给出了Bad请求400.我做错了什么?

http://localhost:23150/Service1.svc/GetData?value=1

GET

服务:

[的ServiceContract] 公共接口IService1 {

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here

}

  public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

1 个答案:

答案 0 :(得分:0)

尝试设计[OperationContract],如下所示:

[OperationContract(Name = "GetData")]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetData?value={value}")]

[OperationContract(Name = "GetData")] [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetData?value={value}")] 现在运行您的服务并从fiddler中选择GET动词并发送请求。我相信它现在会奏效。