namespace WCF_DataReaderService
{
[DataContract]
public class ResultEntry
{
private bool state;
private string message;
private string value;
[DataMember]
public bool State
{
get {
return state; }
set {
state = value; }
}
[DataMember]
public string Message
{
get {
return message; }
set {
message = value; }
}
[DataMember]
public string Value
{
get {
return value; }
set {
this.value = value; }
}
//其他辅助方法省略...
}
}
namespace WCF_DataReaderService
{
[ServiceContract]
public interface IDataReaderService
{
[OperationContract]
[WebInvoke(
Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "ReadFile/FileName={value}"
)]
ResultEntry ReadFile(string value);
[OperationContract]
[WebInvoke(
Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "ConnectTest"
)]
ResultEntry ConnectTest();
}
}
namespace WCF_DataReaderService
{
public class DataReaderService : IDataReaderService
{
public ResultEntry ReadFile(string value)
{
ResultEntry result = ResultEntry.CreateSuccessEntry("");
//调用service层的功能方法
JsonDataFileController controller = new JsonDataFileController();
if (controller.IsFileExist(value) == false)
return result.UpdateState(false, controller.DisplayError_FileNotExsit(value));
if (controller.ReadFileValue(value) == false)
return result.UpdateState(false, controller.DisplayError_FileReadError(value));
result.UpdateResult(controller.Result);
controller.Release();
return result;
}
public ResultEntry ConnectTest()
{
ResultEntry result = ResultEntry.CreateSuccessEntry("this is test");
return result;
}
}
}
namespace WCF_DataReaderService.Controller
{
public class JsonDataFileController
{
public bool IsFileExist(string value)
{
//该类用于读取指定配置文件中写入的“共享路径”
DataFileFoldConfig config = DataFileFoldConfig.Load();
return (File.Exists(config.BaseFold + "/" + value));
}
public bool ReadFileValue(string value)
{
bool result = false;
try
{
DataFileFoldConfig config = DataFileFoldConfig.Load();
string FileName = config.BaseFold + "/" + value;
using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
{
using (StreamReader sw = new StreamReader(fs, Encoding.UTF8))
{
Result = sw.ReadToEnd();
}
}
result = true;
}
catch (Exception ex)
{
Console.WriteLine("ReadFileValue {0} ", ex.Message);
}
return result;
}
public string DisplayError_FileNotExsit(string value)
{
DataFileFoldConfig config = DataFileFoldConfig.Load();
string FileName = config.BaseFold + "/" + value;
return string.Format("文件{0}不存在", FileName);
}
public string DisplayError_FileReadError(string value)
{
DataFileFoldConfig config = DataFileFoldConfig.Load();
string FileName = config.BaseFold + "/" + value;
return string.Format("文件{0} 读取错误", FileName);
}
public string Result {
get; set; }
public void Release()
{
Result = "";
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- 基本配置信息 -->
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<!-- wcf模块信息 -->
<system.serviceModel>
<!-- 允许跨域 -->
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint crossDomainScriptAccessEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
<!-- 申明契约 -->
<services>
<service behaviorConfiguration="WCF_DataReaderService.Behavior(服务行为名)" name="WCF_DataReaderService.DataReaderService(契约实现类全称)">
<endpoint address="http://127.0.0.1:3721/CSQData(网络请求基础路径)" kind="webHttpEndpoint" contract="WCF_DataReaderService.IDataReaderService(请求契约接口类全称)" behaviorConfiguration="WCF_DataReaderService.RestfulBehavior(端口行为配置名)"></endpoint>
</service>
</services>
<!-- 申明行为 -->
<behaviors>
<endpointBehaviors>
<behavior name="WCF_DataReaderService.RestfulBehavior(端口行为配置名)">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WCF_DataReaderService.Behavior(服务行为名)">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!-- 申明参数 -->
<bindings>
<webHttpBinding>
<binding crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
</system.serviceModel>
<!-- 支持jsonp -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET" />
<add name="Access-Control-Allow-Headers" value="x-requested-with,content-type" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
namespace WCF_Host
{
class Program
{
static void Main(string[] args)
{
using (WebServiceHost host = new WebServiceHost(typeof(DataReaderService)))
{
try
{
host.Open();
Console.WriteLine("服务已经启动,输入exit退出...");
while (true)
{
string temp = Console.ReadLine();
if (temp.Equals("exit", StringComparison.CurrentCultureIgnoreCase))
{
break;
}
}
host.Close();
}
catch (Exception ex)
{
Console.WriteLine("服务启动异常{0},输入exit退出...", ex.Message);
}
}
}
}
}
//连接测试函数
function JQuery_ConnectTest()
{
//异步方式获取数据
$.ajax
({
async: false,
crossDomain: true,
type: "get",
url: "http://127.0.0.1:3721/CSQData/ConnectTest",
dataType: 'jsonp',
success: function(data)
{
console.log(0,data);
$("p").text(JSON.stringify(data));
},
error: function(xhr, type)
{
console.log(0,xhr);
}
});
}
//读取文件函数
function JQuery_ReadFile(filePath)
{
//异步方式获取数据
$.ajax
({
async: false,
crossDomain: true,
type: "get",
url: "http://127.0.0.1:3721/CSQData/ReadFile/FileName=" + filePath,
dataType: 'jsonp', //防止跨域的问题
success: function(data)
{
//异步方式获取数据后的处理函数
result = JSON.stringify(data);
//这里只是展示结果
$("p").text(result);
//也可以用传入其他函数,但就是不能执行return语句
JQuery_ReadFile_Post(result);
},
error: function(xhr, type)
{
console.log(0,xhr);
}
});
}
文章浏览阅读1.4k次,点赞24次,收藏18次。在Windows的WSL2中使用图形化应用Chrome,并配置中文界面和输入法。_win11 wsl2 图形化
文章浏览阅读5.5k次,点赞4次,收藏40次。log文件如下所示:代码def read_log(filename): fp=open(filename) for line in fp.readlines(): train_loss=line[-27:-18] train_acc=line[-8:] with open('test.txt','a') as fp2: fp2.write(train_loss+train_acc) fp.close()_python 提取txt中包含loss的行的数据
文章浏览阅读1.4k次。一:WAMPServer的安装 WAMPServer是一个集成开发工具,已经将各个模块配置集成好了,不需要自己去手动配置各种环境。相对自己去分别下载Apache,MySql,PHP软件再去安装配置,要简单快速多了,适合新手使用。W指的是window系统开发环境,A是值Apache,M是指MySql数据库,P是值PHP。 下载成功之后,按照提示_wampsever集成开发环境的安装与配置
文章浏览阅读193次。众所周知,DNS的作用就是将域名转换为IP地址。公网很多DNS服务器不支持IPv6,或者没有完全收录IPv6地址,所以在交大校外访问cgbt.cn有时不能正确的解析为IPv6地址。我们有一个办法来解决,修改HOST表。开始——运行:%systemroot%\system32\drivers\etc打开以上文件夹,看到里边有一个hosts的无扩展名文件用记事本..._2001:da8:205
文章浏览阅读1.8w次,点赞18次,收藏14次。实际开发中遇到个os.system的问题,在偶尔看一本python书中找到解决方法,挺简单的,当时困扰我很长时间,还是经验少啊。在在执行os.system函数的时候通常会阻塞它的调用者,直到所启动的命令行程序退出。在Linux平台上 只需要在命令末尾加上shell后台运算符&即可:os.system('python test.py &')在Windows下,用DO..._python执行卡在os.system
文章浏览阅读3.5k次。原题网址:https://leetcode.com/problems/burst-balloons/Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all t_leetcode 312 312. burst balloons
文章浏览阅读1w次,点赞5次,收藏3次。刚好碰到要下载一个指定版本的android源码,在网上没有找到,所以只能自己去下载,看了谷歌官方下载帮助但是苦于墙抽风,下载速度也奇慢,所以找了几个国内的源头下载,那么跟着我动起来,在这之前你需要一台装有linux的电脑或者是虚拟机上装有linux也是可以的. (一).科普一下git与repo的区别 1. Git:Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项_repo下载安卓源码
文章浏览阅读6.7k次,点赞11次,收藏9次。application.ymlserver: port: 8401spring: application: name: alibaba-sentinel-service cloud: nacos: discovery: server-addr: 192.168.247.111:8848 sentinel: transport: dashboard: localhost:8080 #[配置sentinel d_sentinel1.8请求后实时控制空
文章浏览阅读6.1k次,点赞6次,收藏55次。点击上方“3D视觉工坊”,选择“星标”干货第一时间送达文章导读本文通过一篇YOLT的文章引出超大分辨率的图片遇到目标检测任务该如何处理?此类问题一般出现在遥感领域和医疗影像中居多,我们先来..._16000*16000像素
文章浏览阅读2k次。在ASP.NET中使用Microsoft Word文档[日期:2004-10-04] 来源: CSDN http://dev.csdn.net/develop/article/20/20901.shtm> 作者: [字体: 大 中 小 ] [来源]http://www.codeproject.com/useritems/wordapplication.asp[作者]Mich_asp.net网页能打开word文档vb代码
文章浏览阅读529次。参考文档 Windows平台: http://blog.csdn.net/kudoran/article/details/72650594 https://my.oschina.net/chaloongjir/blog/755954 Mac平台: http://blog.cs..._tolua集成pbc
文章浏览阅读1.3k次。使用LifeData需要添加依赖 // ViewModel and LiveData implementation "android.arch.lifecycle:extensions:1.1.1" // alternatively, just ViewModel implementation "android.arch.lifecycle:viewmodel..._livedata activity和fragment数据共享