資源簡介
客戶端動態鏈接服務端,服務端按用戶名,寫入數據庫不同數據表并生成打印數據返回客戶端打印。
IIS新建網站,設置好IP地址,目錄指向Report_WebService\Report_Service,
在“應用程序池”,點擊該網站,點擊“高級設置”,“啟用32位應用程序”設置為True。
啟動客戶端(client),登錄輸入網址http://xxx.xx.xx.xx/,“/”要輸入完整,
用戶名1001或1002,密碼123456,兩個用戶寫入服務端不同數據表,并打印相應報表。
此例結合https://www.haolizi.net/example/view_37952.html使用參考。
只說明方法的示例,寫的較為粗陋,僅供參考。
public class WebServiceHelper
{
public static string Separator = "[◢℡]"; // 分隔符
public static Type WebService_Type;
public static bool run_service = false;
public static void Get_Service(string url)
{
WebClient web = new WebClient();
Stream stream = web.OpenRead(url "Report.asmx?WSDL");
ServiceDescription description = ServiceDescription.Read(stream);
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap";
importer.Style = ServiceDescriptionImportStyle.Client;
importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
importer.AddServiceDescription(description, null, null);
CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit = new CodeCompileUnit();
unit.Namespaces.Add(nmspace);
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters parameter = new CompilerParameters();
parameter.GenerateExecutable = false;
parameter.GenerateInMemory = true;
CompilerResults result = provider.CompileAssemblyFromDom(parameter, unit);
Assembly asm = result.CompiledAssembly;
WebService_Type = asm.GetType("Report");
run_service = true;
}
public static string Run_ServiceOption(string option, object[] array)
{
object o = Activator.CreateInstance(WebService_Type);
MethodInfo method = WebService_Type.GetMethod(option);
return method.Invoke(o, array).ToString();
}
}
IIS新建網站,設置好IP地址,目錄指向Report_WebService\Report_Service,
在“應用程序池”,點擊該網站,點擊“高級設置”,“啟用32位應用程序”設置為True。
啟動客戶端(client),登錄輸入網址http://xxx.xx.xx.xx/,“/”要輸入完整,
用戶名1001或1002,密碼123456,兩個用戶寫入服務端不同數據表,并打印相應報表。
此例結合https://www.haolizi.net/example/view_37952.html使用參考。
只說明方法的示例,寫的較為粗陋,僅供參考。
public class WebServiceHelper
{
public static string Separator = "[◢℡]"; // 分隔符
public static Type WebService_Type;
public static bool run_service = false;
public static void Get_Service(string url)
{
WebClient web = new WebClient();
Stream stream = web.OpenRead(url "Report.asmx?WSDL");
ServiceDescription description = ServiceDescription.Read(stream);
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap";
importer.Style = ServiceDescriptionImportStyle.Client;
importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;
importer.AddServiceDescription(description, null, null);
CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit = new CodeCompileUnit();
unit.Namespaces.Add(nmspace);
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters parameter = new CompilerParameters();
parameter.GenerateExecutable = false;
parameter.GenerateInMemory = true;
CompilerResults result = provider.CompileAssemblyFromDom(parameter, unit);
Assembly asm = result.CompiledAssembly;
WebService_Type = asm.GetType("Report");
run_service = true;
}
public static string Run_ServiceOption(string option, object[] array)
{
object o = Activator.CreateInstance(WebService_Type);
MethodInfo method = WebService_Type.GetMethod(option);
return method.Invoke(o, array).ToString();
}
}
代碼片段和文件信息
using?System.Runtime.Serialization.Json;
using?System.IO;
using?System.xml.Serialization;
using?System.xml;
using?System.Runtime.Serialization.Formatters.Binary;
public?class?Client_Serializer
{
????///?將對象序列化為json文件
????public?static?void?objectToJson(T?t?string?path)?where?T?:?class
????{
????????DataContractJsonSerializer?formatter?=?new?DataContractJsonSerializer(typeof(T));
????????using?(FileStream?stream?=?new?FileStream(path?FileMode.OpenOrCreate))
????????{
????????????formatter.Writeobject(stream?t);
????????}
????}
????///?將對象序列化為json字符串
????public?static?string?objectToJson(T?t)?where?T?:?class
????{
????????DataContractJsonSerializer?formatter?=?new?DataContractJsonSerializer(typeof(T));
????????using?(MemoryStream?stream?=?new?MemoryStream())
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????61952??2020-02-09?00:11??Client\.vs\Client\v16\.suo
?????文件??????????0??2020-02-08?09:39??Client\.vs\Client\v16\Server\sqlite3\db.lock
?????文件?????663552??2020-02-09?00:11??Client\.vs\Client\v16\Server\sqlite3\storage.ide
?????文件????????189??2020-02-08?09:39??Client\Client\App.config
?????文件??????24064??2020-02-09?00:04??Client\Client\bin\Debug\Client.exe
?????文件????????189??2020-02-08?09:39??Client\Client\bin\Debug\Client.exe.config
?????文件??????56832??2020-02-09?00:04??Client\Client\bin\Debug\Client.pdb
?????文件?????243712??2019-12-27?21:33??Client\Client\bin\Debug\contextUI.dll
?????文件?????419328??2020-02-04?10:06??Client\Client\bin\Debug\RptBuild.dll
?????文件?????256000??2020-01-09?12:44??Client\Client\bin\Debug\websocket-sharp.dll
?????文件???????4771??2020-02-08?21:52??Client\Client\Client.csproj
?????文件???????4550??2020-02-08?21:52??Client\Client\Client_Serializer.cs
?????文件???????5311??2020-02-09?00:03??Client\Client\Form1.cs
?????文件??????25987??2020-02-08?22:55??Client\Client\Form1.Designer.cs
?????文件???????5817??2020-02-08?22:55??Client\Client\Form1.resx
?????文件???????1343??2020-02-08?22:00??Client\Client\login.cs
?????文件???????7110??2020-02-08?21:59??Client\Client\login.Designer.cs
?????文件???????5817??2020-02-08?21:59??Client\Client\login.resx
?????文件??????????0??2020-02-09?00:04??Client\Client\obj\Debug\Client.csproj.CopyComplete
?????文件????????580??2020-02-08?23:56??Client\Client\obj\Debug\Client.csproj.FileListAbsolute.txt
?????文件???????1070??2020-02-08?23:56??Client\Client\obj\Debug\Client.csproj.GenerateResource.cache
?????文件??????24064??2020-02-09?00:04??Client\Client\obj\Debug\Client.exe
?????文件????????180??2020-02-08?23:56??Client\Client\obj\Debug\Client.Form1.resources
?????文件????????180??2020-02-08?23:56??Client\Client\obj\Debug\Client.login.resources
?????文件??????56832??2020-02-09?00:04??Client\Client\obj\Debug\Client.pdb
?????文件????????180??2020-02-08?23:56??Client\Client\obj\Debug\Client.Properties.Resources.resources
?????文件???????1435??2020-02-08?14:10??Client\Client\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7507??2020-02-08?21:51??Client\Client\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????683??2020-02-08?10:22??Client\Client\Program.cs
?????文件???????1304??2020-02-08?09:39??Client\Client\Properties\AssemblyInfo.cs
............此處省略251個文件信息
評論
共有 條評論