我正在从7天wcf工作。我创建了一个Wcf服务。 但工作正常,并通过添加服务参考在Visual Studio中得到响应。但我的问题是,无论何时它被整合到android/windows中,这些人都没有得到回应。他们得到400(坏请求)。请任何人帮助我如何得到适当的回应。 (我想作为JSON响应)这是我的下面的代码。 预先感谢您。WCF服务:400个错误的请求?
接口
public interface ISampleService1
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "getdata",BodyStyle = WebMessageBodyStyle.Bare)]
string getdata();
}
类
public string getdata()
{
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";
}
web.config文件:
<?xml version="1.0"?>
<configuration>
<appSettings/>
</connectionStrings>
<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="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service behaviorConfiguration="SampleWcfproject.SampleService1Behavior" name="SampleWcfproject.SampleService1">
<endpoint address="" 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="false"/>
</behavior>
<behavior name="SampleWcfproject.SampleService1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我被消耗Web引用项目获得Visual Studio中的以下respomse。但在android中出现400错误。
[{“”CircleID“”:1,“”CircleName“”:“”Andhra Pradesh“”},{“”CircleID“”:4,“”CircleName“”“”Assam“”}, { “” CircleID “”:5 “” CIRCLENAME “”: “” 比哈尔邦 “”},{ “” CircleID “”:6 “” CIRCLENAME “”: “” 奈 “”},{ “” CircleID “” :7 “” CIRCLENAME “”: “” 德里 “”},{ “” CircleID “”:8 “” CIRCLENAME “”: “” 古吉拉特 “”},{ “” CircleID “”:9 “” CIRCLENAME “”:“”Himachal Pradesh“”},{“”CircleID“”:10,“”CircleName“”:“”Haryana“”},{“”CircleID“”:11,“”CircleName“”:“” Jammu \ Kashmir“”},{“”CircleID“”:12,“”CircleName“”:“”Kerala“”},{“”CircleID“”:13,“”CircleName“”:“”Karnataka“” },{ “” CircleID “”:14 “” CIRCLENAME “”: “” 加尔各答 “”},{ “” CircleID “”:15 “” CIRCLENAME “”: “” 邦 “”},{ “” CircleID “”:16,“”CircleName“”“”Madhya Pradesh“”},{“”CircleID“”:17,“”CircleName“”:“”Mumbai“”},{“”CircleID“”: “”CircleName“”:“”North East“”},{“”CircleID“”:19,“”CircleName“”:“”Orissa“”},{“CircleID”“:20,”“CircleName”“ : “” 旁遮普 “”},{ “” CircleID “”:21 “” CIRCLENAME “”: “” Rajas比 “”},{ “” CircleID “”:22 “” CIRCLENAME “}]”);
这是我的网址 http://xyzmnmkljj.in/SampleService1.svc/getdata
但它提供了400错误的请求。
在web.comfig文件的任何修改,请帮我
请antone帮我 –