C# 400在使用wcf服务时请求错误?

C# 400在使用wcf服务时请求错误?,c#,android,wcf,wcf-configuration,C#,Android,Wcf,Wcf Configuration,我开发了一个wcf服务。使用该服务时,它在我的本地运行良好。但发生了什么事,该服务发布在服务器上。然后,每当使用该服务时,都会收到400个错误请求。请帮助我 下面是我的代码: namespace SampleWcfproject { [ServiceContract] public interface ISampleService1 { [OperationContract] //[WebInvoke(Method="GET",Resp

我开发了一个wcf服务。使用该服务时,它在我的本地运行良好。但发生了什么事,该服务发布在服务器上。然后,每当使用该服务时,都会收到400个错误请求。请帮助我

下面是我的代码:

namespace SampleWcfproject
{
    [ServiceContract]
    public interface ISampleService1
    {
         [OperationContract]
         //[WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="getdata")]
         [WebInvoke(UriTemplate = "/getdata/{uuid}", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
         string getdata(string uuid);

         [OperationContract]
         string getcities();
    }
}
sampleservice.svc.cs:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class SampleService1 : ISampleService1
{
      public  string getdata(string uuid)
      {
          try
          {


                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con2"].ConnectionString);
                SqlCommand comm = new SqlCommand("select CircleID, CircleName from Circle", con);
                con.Open();
                comm.ExecuteNonQuery();

                SqlDataAdapter da = new SqlDataAdapter(comm);
                // DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                da.Fill(dt);

                JavaScriptSerializer JSSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                List<Dictionary<string, object>> DtRows = new List<Dictionary<string, object>>();
                Dictionary<string, object> newrow = null;

                //Code to loop each row in the datatable and add it to the dictionary object
                foreach (DataRow drow in dt.Rows)
                {
                    newrow = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        newrow.Add(col.ColumnName.Trim(), drow[col]);
                    }
                    DtRows.Add(newrow);
                }
                con.Close();


                return JSSerializer.Serialize(DtRows);
            }
            catch (Exception ex)
            {

                List<String> Parameters = new List<String>();
                Parameters.Add("getRechargeCircleList");

             //   SendErrorMail(ex.ToString(), "getRechargeCircleList", Parameters);
               // Context.Response.ContentType = "application/json; charset=utf-8";
               // Context.Response.Write(@" {""Status"":""false"",""Message"" : ""Oops! Something went Wrong""}");
               // return;
            }
            return "false";
       }
     }
}
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
公共类SampleService1:ISampleService1
{
公共字符串getdata(字符串uuid)
{
尝试
{
SqlConnection con=新的SqlConnection(ConfigurationManager.ConnectionString[“con2”].ConnectionString);
SqlCommand comm=新SqlCommand(“从圆圈中选择圆圈ID、圆圈名称”,con);
con.Open();
comm.ExecuteNonQuery();
SqlDataAdapter da=新的SqlDataAdapter(comm);
//数据集ds=新数据集();
DataTable dt=新的DataTable();
da.填充(dt);
JavaScriptSerializer JSSerializer=new System.Web.Script.Serialization.JavaScriptSerializer();
List DtRows=新列表();
字典newrow=null;
//循环datatable中的每一行并将其添加到dictionary对象的代码
foreach(数据行中的数据行drow)
{
newrow=新字典();
foreach(dt.列中的数据列列列)
{
Add(col.ColumnName.Trim(),drow[col]);
}
DtRows.Add(newrow);
}
con.Close();
返回JSSerializer.Serialize(DtRows);
}
捕获(例外情况除外)
{
列表参数=新列表();
参数。添加(“GetRecurgeCircleList”);
//SendErrorMail(例如ToString(),“GetRecurgeCircleList”,参数);
//Context.Response.ContentType=“application/json;charset=utf-8”;
//Context.Response.Write(@“{”状态“:”错误“,”消息“:”糟糕!出了问题“}”);
//返回;
}
返回“false”;
}
}
}
web.config文件:

<system.web>

    <httpRuntime maxRequestLength="32768"/>
    <compilation debug="true" targetFramework="4.0"/>
     <customErrors mode="Off"/>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
   <authentication mode="Windows"/>
    <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
    -->
    <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>
  </system.web>
  <!-- 
      The system.webServer section is required for running ASP.NET AJAX under Internet
      Information Services 7.0.  It is not necessary for previous version of IIS.
  -->
  <system.webServer>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
  <system.serviceModel>

    <bindings>
    <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="4194304" 
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000">
            <readerQuotas maxDepth="32" 
                 maxArrayLength="200000000"
                 maxStringContentLength="200000000"/>
        </binding>
    </basicHttpBinding>
</bindings>
    <services>
      <service behaviorConfiguration="SampleWcfproject.Service1Behavior" name="SampleWcfproject.Service1">
        <endpoint address="" binding="basicHttpBinding" contract="SampleWcfproject.IService1">

          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>

        <endpoint address="" binding="netTcpBinding" contract="SampleWcfproject.IService1"/>

          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
      <service behaviorConfiguration="SampleWcfproject.SampleService1Behavior" name="SampleWcfproject.SampleService1">
        <endpoint address="basic" binding="basicHttpBinding" contract="SampleWcfproject.ISampleService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
       <endpointBehaviors>
            <behavior name="web">
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="SampleWcfproject.Service1Behavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <behavior name="SampleWcfproject.SampleService1Behavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

实际上,这个服务在我的.net项目中运行得很好。我通过使用add service reference添加这个服务并正常获取数据。但是每当我使用HttpWebRequest时,就会出现400个badrequest。我该怎么办?我不知道发生了什么

更新:


我在我的windows phone应用程序中收到响应。但是android用户出现了错误。他们得到了html响应。例如,我的wcf调试浏览器页面。

请像这样修改
服务模型配置

删除



@KishoreSahas如何定义端点地址和where@KishoreSahas端点地址表示“url”使用WcfTestClient.exe测试是,wcf url以
.svc
结尾,测试该url(请参阅上一条注释)我正在创建wcf服务。该服务已被andriod用户使用。但他们出现错误。他们正在获取html页面。请起草一个新页面,我将进行检查,并在此处删除注释。我不会更改任何代码。我在我的windows phone应用程序中得到了响应。但是android用户得到了错误。他们得到了html响应。html设计是我的wcf webservice调试页面。是的,这就是我在这里所说的问题标记c#和asp.net,所以需要在新问题中添加windows phone标记,我对mmobiles没有正确的了解抱歉!!让我们。
   <service behaviorConfiguration="SampleWcfproject.Service1Behavior" name="SampleWcfproject.Service1"> 

    <endpoint address="" binding="basicHttpBinding" contract="SampleWcfproject.IService1"> 

  <identity> 
 <dns value="localhost"/> 
  </identity> 
  </endpoint> 

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service>