2017-02-06 17 views
0

У меня есть wcf webservice, когда я нахожусь в webservice в POST menthod от android, значение, которое я получаю в сервисе, равно null.Передача строки с android на wcf restful service получает нуль

Файл CS приводится ниже:

[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "Login", BodyStyle = WebMessageBodyStyle.Bare)] string Login(Student Student); public class Student { [DataMember(Name = "image")] public string image { get; set; } }

Файл конфигурации приведен ниже

<system.web.extensions> 
<scripting> 
    <webServices> 
    <jsonSerialization maxJsonLength="2147483647" /> 
    </webServices> 
</scripting> 
</system.web.extensions> 
<system.net> 
    <defaultProxy enabled="true" useDefaultCredentials="true"> </defaultProxy> 
</system.net> 
<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
<httpRuntime targetFramework="4.0" /> 

</system.web> 

<system.serviceModel> 
<services> 

    <service name="ESIService.Service1" behaviorConfiguration="ServiceBehaviour"> 
    <endpoint address="" binding="webHttpBinding" contract="ESIService.IService1" behaviorConfiguration="web"/> 

</service> 
</services> 


<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IService1" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered" useDefaultWebProxy="true"> 

     <readerQuotas maxDepth="500" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
    </bindings> 

<behaviors> 
    <serviceBehaviors> 
    <behavior name="ServiceBehaviour"> 

     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 

     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <serviceThrottling maxConcurrentCalls="16" maxConcurrentInstances="41" maxConcurrentSessions="100"/> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="web"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

<protocolMapping> 
    <add binding="basicHttpsBinding" scheme="https" /> 
</protocolMapping> 

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false"/> 
</system.serviceModel> 

    <system.webServer> 
<directoryBrowse enabled="true" /> 
<defaultDocument> 
    <files> 
    <add value="Service1.svc" /> 
    </files> 
</defaultDocument> 
    <validation validateIntegratedModeConfiguration="false" /> 
</system.webServer> 
</configuration>` 

Файл SVC дается ниже, когда я бегу я получаю идентификатор значение равно null.

public string Login(Student Student) { String id = Student.image;}

Андроида код приведен ниже:

JSONStringer item = new JSONStringer() 
       .object() 
       .key("Student") 
       .object() 
       .key("image").value("abcd") 
       .endObject() 
       .endObject(); 

URL утра ударять это .../Вход

ответ

0

Я не знаком с андроид develeopment, но так как у вас есть BodyStyle = WebMessageBodyStyle.Bare, служба ожидает следующую строку json в теле запроса:

{ "образ": "ABCD"}

Возможно, это будет работать:

JSONStringer item = new JSONStringer() 
       .object() 
       .key("image").value("abcd") 
       .endObject();