Я работаю над wcf с 7 дней. Я создал одну услугу Wcf. Но отлично работает и получил ответ в визуальной студии, добавив ссылку на службу. Но моя проблема - всякий раз, когда она интегрирована в 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>
я получаю ниже respomse в визуальной студии, потребляя веб-справочный проект. Но получить ошибку, как 400 в Android.
[{"" CircleID "": 1, "CircleName" ":" "Andhra Pradesh" "}, {" "CircleID" ": 4," CircleName "": "" Assam ""} { "" CircleID "": 5 "" CIRCLENAME "": "" Бихар ""}, { "" CircleID "": 6 "" CIRCLENAME "": "" Ченнаи ""}, { "" CircleID "" : 7 "" CIRCLENAME "": "" Delhi ""}, { "" CircleID "": 8 "" CIRCLENAME "": "" Гуджарат ""}, { "" CircleID "": 9 "" CIRCLENAME «« CircleID »": 10, "CircleName" ":" Haryana ""}, {"" CircleID "": 11, "CircleName" ":" " Джамму Кашмира ""}, {"" CircleID ": 12," CircleName "": "" Kerala ""}, {"" CircleID "": 13, "CircleName" ":" "Karnataka" " }, { "" CircleID "": 14 "" CIRCLENAME "": "" Калькутта ""}, { "" CircleID "": 15 "" CIRCLENAME "": "" Махараштра ""}, { "" CircleID "": 16, "CircleName" ":" "Madhya Pradesh" "}, {" "CircleID": 17, "CircleName" ":" "Mumbai" "}, {" "CircleID" ": 18, «CircleName» ":" "North East" "}, {" "CircleID" ": 19," CircleName "": "" Orissa ""}, {"" CircleID "": 20, "CircleName" " : "" Пенджаб ""}, { "" CircleID "": 21 "" CIRCLENAME "": "" Раджас чем ""}, { "" CircleID "": 22 "" CIRCLENAME "}]");
это мой URL http://xyzmnmkljj.in/SampleService1.svc/getdata
но это дает 400 плохой запрос.
Любые изменения в web.comfig файле, пожалуйста, помогите мне
, пожалуйста, antone help me –