Я разработчик C# .Net я сейчас программирования успокоительной службы ФОС для связи мобильного с моим сервером. Но проблема в отправке json request using post метод с параметром. После отправки запроса от клиента, сервер ошибок дисплея: 400 Bad Request ...ФОС Restful службы после имени пользователя с параметром
Мой контракт обслуживание:
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json, UriTemplate = "login", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
string login(string username, string password);
и осуществлять обслуживание:
public string login(string username, string password)
{
string str = String.Empty;
if (username == "admin" && password == "admin")
str = "Success";
else
str = "Invalid";
return str;
}
Редактировать:
Мой хозяин:
public void Start()
{
Stop();
//string strAdrHTTP = "http://localhost:" + HttpPort + "/WcfMobileService";
string strAdrHTTP = "http://192.168.1.190:" + HttpPort + "/WcfMobileService";
Uri[] adrbase = { new Uri(strAdrHTTP) };
m_svcHost = new ServiceHost(typeof(TWcfMobileService), adrbase);
WebServiceHost webServiceHost =
new WebServiceHost(typeof(TWcfMobileService), adrbase);
ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();
m_svcHost.Description.Behaviors.Add(mBehave);
mBehave.HttpsGetEnabled = true;
mBehave.HttpGetEnabled = true;
WebHttpBinding webBinding = new WebHttpBinding();
webServiceHost.AddServiceEndpoint(typeof(IWcfMobileServiceContract), webBinding, "rest");
WebHttpBinding restBinding = new WebHttpBinding();
ServiceEndpoint restSEP =
m_svcHost.AddServiceEndpoint(typeof(IWcfMobileServiceContract),
restBinding, "rest");
restSEP.Behaviors.Add(new WebHttpBehavior());
EndpointAddress myEndpointAdd = new EndpointAddress(new Uri(strAdrHTTP),
EndpointIdentity.CreateDnsIdentity("localhost"));
restSEP.Address = myEndpointAdd;
m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
ServiceDebugBehavior debug = new ServiceDebugBehavior();
debug.IncludeExceptionDetailInFaults = true;
m_svcHost.Open();
}
удалить 'Bodystyle = WebMessageBodyStyle.WrappedRequest' –
@AmitKumarGhosh Не работают –