c# – 在Asp.Net MVC项目中托管WCF服务
发布时间:2020-12-15 04:17:21 所属栏目:百科 来源:网络整理
导读:我有一个解决方案有3个项目: ConsoleClient(用于测试WCF服务) ServiceLibrary(适用于WCF) Web(asp.net mvc项目) 我在app.config中的ServiceLibrary项目中做了一些设置 system.serviceModel services service name="MrDAStoreJobs.ServiceLibrary.Advertisem
我有一个解决方案有3个项目:
> ConsoleClient(用于测试WCF服务) 我在app.config中的ServiceLibrary项目中做了一些设置 <system.serviceModel> <services> <service name="MrDAStoreJobs.ServiceLibrary.AdvertisementService"> <clear /> <endpoint address="http://localhost:8050/ServiceLibrary/basic" binding="basicHttpBinding" bindingConfiguration="" contract="MrDAStoreJobs.ServiceLibrary.Interface.IAdvertisementService" /> <host> <baseAddresses> <add baseAddress="http://localhost:8050/Design_Time_Addresses/MrDAStoreJobs/ServiceLibrary/AdvertisementService/" /> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information,set the value below to false 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> </system.serviceModel> 当我运行这个项目时,似乎通常使用wcf测试客户端. 现在,我还在我的Web项目(mvc)中添加了一个WcfDataServiceTest.svc来托管我的wcf服务. 所以我的问题是: >我的web项目(web.config)实际托管这个wcf服务需要什么配置? 注意:我已经使用控制台项目测试了我的服务,但正在从WCF测试客户端获取代理生成. 顺便说一下,wcfDataServiceTest.svc文件如下所示: public class WcfDataServiceTest : DataService<AdvertisementService> { // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { // TODO: set rules to indicate which entity sets and service operations are visible,updatable,etc. // Examples: config.SetEntitySetAccessRule("Advertisements",EntitySetRights.AllRead); // config.SetServiceOperationAccessRule("MyServiceOperation",ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } } 解决方法
我在我的MVC项目中直接托管一个WCF服务.下面是一个通用的例子:
Web.config服务配置: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="customBinding0"> <binaryMessageEncoding /> <httpTransport /> </binding> </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="1048576"> <readerQuotas maxStringContentLength="1048576" /> </standardEndpoint> </webHttpEndpoint> </standardEndpoints> </system.serviceModel> 这是服务类: [ServiceContract] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class MyService { [OperationContract] [WebInvoke(UriTemplate = "{personId}",Method = "GET")] public Person Get(string personId) { return new Person(); } } 这里是我在我的MVC Global.asax中注册的地方 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); RouteTable.Routes.Add(new ServiceRoute("SVC/My",new WebServiceHostFactory(),typeof(MyService))); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 未定义的局部变量或方法`root_path’Hart
- ios – 无法通过Jenkins上的xcodebuild从命令行执行测试
- ajax 跨域请求处理
- Nodejs express框架一个工程中同时使用ejs模版和jade模版
- Swift 设置navigationbar属性相关
- vue如何引用其他组件(css和js)
- Swift详解之一 -------- 变量声明
- Identifying multiple/single values of metadata and reco
- ruby-on-rails – 按rspec中的种子顺序列出所有规格
- ios – 在任何具体目标中不使用依赖关系“AFNetworking(?>