详细介绍基于MySQL的搜索引擎MySQL-Fullltext

2019-01-05 09:56:37王振洲

我们将实现定义在 "App-Code/IVisionService.cs"中:
 

namespace VisionServices { public class PInvoke { [DllImport("VisionDAL.dll", CharSet = CharSet.Unicode)] public static extern string GetDocuments(string search, int format, int forAutocomplete); } public class VisionService : IVisionService { public string GetDocuments(string search, int format, int forautocomplete) { string result = PInvoke.GetDocuments(search, format, forautocomplete).ToString(); return result; } } }

VisionService.svc的实现

 

<%@ ServiceHost Language="C#" Debug="true" Service="VisionServices.VisionService" CodeBehind="App_CodeVisionService.cs" %>

这里定义了调用"http://<your webserver>:<your port>VisionService.svc"时的服务端点 ,调用GetDocuments函数的URL地址是 "http://<your webserver>:<your port>VisionService.svc/GetDocuments"。

Web.config 文件
 

<?xml version="1.0"?> <configuration> <appSettings/> <system.web> <httpRuntime/> <compilation debug="true"/> </system.web> <system.serviceModel> <services> <service name="VisionServices.VisionService"> <endpoint address="" binding="webHttpBinding" contract="VisionServices.IVisionService" behaviorConfiguration="webHttpEndpoint"/> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="webHttpEndpoint"> <webHttp helpEnabled="true"/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <directoryBrowse enabled="true"/> </system.webServer> </configuration>

这是允许Ajax请求的配置。 你可以使用很多选项来配置WCF。你可以到Safari上查看更多类似于[2]的文档。

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>配置了一个提供元数据交换的端点,通过元数据你可以自动生成代码来获得WebService代理,比如使用svcutil。选择"Programs/Microsoft Visual Studio 2012/Visual Studio Tools/Developer Command Prompt for VS2012". 输入svcutil http://localhost:8001/VisionService.svc.一个名为VisionService.cs 的文件就生成了, 在其他情况下也会生成一个包含了Webservice配置信息的文件。