wcf服务返回错误404 POST请求

时间:2015-11-02 20:28:09

标签: c# wcf post

我有客户端(Windows Phone),我有REST服务。问题是:我发送一个POST请求,其中一个变量JSON字符串服务处理它,答案来了:

    "{StatusCode: 404, ReasonPhrase: '', Version: 0.0, Content: System.Net.Http.StreamContent, Headers:{  Content-Length: 0}}"

我有很长时间试图找出答案。没有所有人的帮助。所以,所有阶段: 1)我发布的变量:

          "{"Category_id":1002,"Country_id":null,"City_id":null,"Areas_id":null,"Gender_user":null,"DateAnnouncing":null,"MinDateBirthday":null,"MaxDateBirthday":null,"Popular":null,"DateSort":null}"

2)通话方法

    public static async Task<string> ServiceCalledWithJson( string MethodName, AnnFilter customObject)
    {
        string ServiceURI = GetServiceHost() + MethodName;                                 
        var httpClient = new HttpClient();
        var result = JsonConvert.SerializeObject(new { filter = customObject });
        var request = new StringContent(result, Encoding.UTF8, "application/json");
        var response = await httpClient.PostAsync(ServiceURI, request);
        string content = await response.Content.ReadAsStringAsync();
        return content;
    }

3)在界面

    [OperationContract]
    [WebInvoke(Method = "POST",ResponseFormat =WebMessageFormat.Json,BodyStyle =WebMessageBodyStyle.WrappedRequest)]
    List<Announcing> GetAnnouncingFilter(AnnFilter filter);

4)功能

    public List<Announcing> GetAnnouncingFilter(AnnFilter filter)
    {
        var json = JsonConvert.SerializeObject(filter);
        Logger.WriteToFile_Json(json);
        List < Announcing > listAnnonc = new List<Announcing>();
        Announcing annonc = new Announcing();
        DataTable table = new DataTable();
        table = AnnouncingFilter.GetAnnouncingFilter(filter);
        foreach(DataRow row in table.Rows)
        {
            try
            {
                annonc.Announcing_id = int.Parse(row["Announcing_id"].ToString());
                annonc.Name_Announcing = row["Name_Announcing"].ToString();
                annonc.Name_City = row["City_Name"].ToString();
                listAnnonc.Add(new Announcing() {Announcing_id=annonc.Announcing_id,Name_Announcing=annonc.Name_Announcing,Name_City =annonc.Name_City });
            }
            catch (Exception ex)
            {
                Logger.CreateLog(ex);
                throw ex;
            }
        }
        var slem = "";
        slem = JsonConvert.SerializeObject(listAnnonc);
        Logger.WriteToFile_Json(slem);
        return listAnnonc;

5)记录

    {"Category_id":1002,"Country_id":null,"City_id":null,"Areas_id":null,"Gender_user":null,"DateAnnouncing":null,"MinDateBirthday":null,"MaxDateBirthday":null,"Popular":null,"DateSort":null

   [{"Name_City":"Киев","Announcing_id":1,"Name_Announcing":"Прогулки","Phone_Announcing":null,"Date_Announcing":"0001-01-01T00:00:00","Info_Announcing":null,"Categories_id":0,"User_id":0,"City_id":0,"Areas_id":null,"AreasOfCity":null,"Categories":null,"Cities":null,"UserList":null,"Favorite_Announcing":[],"Selected_Announcing":[]}]

6)网络配置:

    <endpointBehaviors>
    <behavior name="restBehavior">
      <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json"/>
    </behavior>
  </endpointBehaviors>
    <service behaviorConfiguration="MyBehavior" name="Searching.BE.Service.WCFRESTService">
        <endpoint address="" behaviorConfiguration="restBehavior" binding="webHttpBinding"
            contract="Searching.BE.Service.IWCFRESTService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <endpoint address="net" binding="netHttpBinding" contract="Searching.BE.Service.IWCFRESTService">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
    <webHttpBinding>
      <binding name="webhttp"
        bypassProxyOnLocal="true"
        useDefaultWebProxy="false"
        hostNameComparisonMode="WeakWildcard"
        sendTimeout="10:15:00"
        openTimeout="10:15:00"
        receiveTimeout="10:15:00"
        maxReceivedMessageSize="2147483647"
        maxBufferSize="2147483647"
        maxBufferPoolSize="2147483647"
        transferMode="StreamedRequest">
        <readerQuotas maxArrayLength="2147483647"
                      maxStringContentLength="2147483647" />
        <security mode="None">
          <transport clientCredentialType="None">
          </transport>
        </security>
      </binding>
    </webHttpBinding>

0 个答案:

没有答案