如何从WCF Serivce调用获取Android应用程序参数 [英] How To call get Android App Parameter From WCF Serivce

查看:79
本文介绍了如何从WCF Serivce调用获取Android应用程序参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WCF新建所以任何人帮助我



我的任务是为Android应用程序创建WCF服务



从Android应用程序获取数据Anmd将其保存到SQL服务器中使用WCF服务



我的代码是Iservice.cs



I New In WCF So Anybody Help Me

My Task is To Create WCF Service For Android App

Get Data From Android App Anmd Save It Into SQL server Using WCF service

My code IS Iservice.cs

[OperationContract]
        [WebGet(UriTemplate = "/GetBarCodeData/{barcode}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
        [return: MessageParameter(Name = "barcode")]
        string GetBarCodeData(string barcode);





Service1.svc.cs





Service1.svc.cs

public string  GetBarCodeData(string barcode)
        {
       
            SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("Insert Into Emp(Ename)values('" + barcode + "')");
            SqlDataAdapter sdap = new SqlDataAdapter();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.ExecuteNonQuery();
            // flag = true;
            //dataset ds = new dataset();
            //sqldataadapter sqldataadapter = new sqldataadapter(sqlcommand);
            //sqldataadapter.fill(ds);
            sqlConnection.Close();
            return barcode;
}





网络配置



Web Config

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <connectionStrings>
    <add name ="ConnectionString" providerName ="System.Data.SqlClient" ;persist security info=True;multipleactiveresultsets=True;"/>
  </connectionStrings>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

推荐答案

首先,如果你想从Android应用程序获取数据并存储在数据库中,然后创建一个wcf服务,然后在接口中定义[OperationContract],如下所示



first of all if you want to get data from android app and store in database , then create a wcf service , then define [OperationContract] in interface like below

[OperationContract]
[WebInvoke(UriTemplate = "/GetBarCodeData/{barcode}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
string GetBarCodeData(string barcode);





然后写入.svc.cs中的逻辑,用于在服务器中插入数据(与传统方式一样)



现在转到web.config文件

in< system.servicemodel>定义终点和行为



then write the logic in .svc.cs for inserting data in server (Like traditional way)

now go to web.config file
in <system.servicemodel> define end points and behaviours

<pre> <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding bypassProxyOnLocal="true" useDefaultWebProxy="false" hostNameComparisonMode="WeakWildcard" sendTimeout="10:15:00" openTimeout="10:15:00" receiveTimeout="10:15:00" maxBufferSize="2147483647" transferMode="StreamedRequest" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </webHttpBinding>
    </bindings>

    <services>
      <service name="Pojectname.serviceclassname" behaviorConfiguration="Pojectname.serviceclassnameBehavior">
        <endpoint address="" binding="webHttpBinding" contract="Pojectname.serviceinterfacename" behaviorConfiguration="webBehaviour" />
        <endpoint name="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="Pojectname.serviceclassnameBehavior">
          <!-- 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="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehaviour">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel

>



希望它能为您提供帮助。

>

hope it will help you.


这篇关于如何从WCF Serivce调用获取Android应用程序参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆