0

我有一个 android 应用程序,它点击了我的 api ..下面是登录后 api ......当我通过我的应用程序点击 api 时,它显示出了问题错误......当我通过邮递员点击我的 api ..它显示“415无法处理 ...text/xml charset=utf-8'" 错误..

我的服务.svc.cs

public WebResponse ValidateUser(WebRequest valid)
    {
         WebResponse objWebResponse = new WebResponse();
         // webRequestdto objData = new webRequestdto();
         //objData = JsonConvert.DeserializeObject<webRequestdto>(valid.data);     

        try
        {           
           var sqlQuery = string.Empty;
           DataTable obj = null;             
           if (!string.IsNullOrEmpty(valid.Username) &&!string.IsNullOrEmpty(valid.Password))
          //if (!string.IsNullOrEmpty(valid.data))
            {
               sqlQuery = @"select gen_users.UserId, gen_users.MobileNo, gen_users.EmailID, concat(Firstname, ' ', Lastname) as FullName from gen_users
                        where gen_users.Username='{0}' and gen_users.UserPassword = reverse('{1}') and gen_users.IsActive='Y'";

                sqlQuery = string.Format(sqlQuery, valid.Username, valid.Password);
                obj = DbHelper.ExecuteDataset(Globals.GetConnectionString(), CommandType.Text, sqlQuery).Tables[0];                   
            }
                if (obj.Rows.Count > 0)
                {                    
                objWebResponse.userid = Convert.ToInt32(obj.Rows[0]["UserId"]);                    
                objWebResponse.EmailID = Convert.ToString(obj.Rows[0]["EmailID"]);
                objWebResponse.FullName = Convert.ToString(obj.Rows[0]["FullName"]);
                objWebResponse.MobileNo = Convert.ToString(obj.Rows[0]["MobileNo"]);
                objWebResponse.status = "success";

                return objWebResponse;
                }
            else
            {
                objWebResponse.status = "fail";
                objWebResponse.userid = 0;
               return objWebResponse;                   
            }
        }
        catch (Exception ex)
        {
         throw new FaultException(ex.Message);
        }
    }

我的服务.cs

[OperationContract]
    [WebInvoke(UriTemplate = "ValidateUser",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json, Method = "POST")]
    WebResponse ValidateUser(WebRequest valid);

网络配置

<?xml version="1.0" encoding="utf-8"?>
    <configuration>

        <appSettings>
            <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
            <add key="*" value="Server=*;Database=*;User ID=*;Password=*;" />
        </appSettings>
        <system.web>
            <compilation debug="true" targetFramework="4.5.2"/>
            <httpRuntime targetFramework="4.5.2"/>
            <httpModules>
                <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
            </httpModules>
        </system.web>
        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
                        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                        <serviceDebug includeExceptionDetailInFaults="false"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <protocolMapping>
                <add binding="basicHttpsBinding" scheme="https"/>
            </protocolMapping>    
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
        </system.serviceModel>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true">
                <remove name="ApplicationInsightsWebTracking"/>
                <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
            </modules>

            <directoryBrowse enabled="true"/>
            <validation validateIntegratedModeConfiguration="false"/>
        </system.webServer>

    </configuration>
4

0 回答 0