我如何可以承载一个WCF服务,而不在IIS中SVC文件 [英] How can I host a WCF service without an SVC file in IIS
问题描述
我想部署一个双接口(SOAP / REST / XML / JSON)在IIS WCF服务在网址只是一个配置文件和二进制文件,并没有SVC文件
I'd like to deploy a dual interface (SOAP/REST/XML/JSON) WCF service in IIS with just a config file and the binaries and no svc file in the URL
我们使用VS2012和.NET 4.5
We use VS2012 and .Net 4.5
我们有类似的东西的工作,我也跟着导游在这里:
<一href=\"http://blogs.msdn.com/b/rjacobs/archive/2010/04/05/using-system-web-routing-with-data-services-odata.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/rjacobs/archive/2010/04/05/using-system-web-routing-with-data-services-odata.aspx
We have something like it working, I followed a guide here: http://blogs.msdn.com/b/rjacobs/archive/2010/04/05/using-system-web-routing-with-data-services-odata.aspx
我添加了一个全局类
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
DataServiceHostFactory factory = new DataServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("wrap", factory, typeof(NeOtheWrapper)));
}
}
和我用我现有的web.config它定义了所有端点:
And I used my existing web.config which defines all the endpoints:
<system.serviceModel>
<!-- Clients -->
<client>
<endpoint name="MySoftLive" address="https://backof.somewebsitett.com/Cmp.MySoft.bl/MySoft.svc" binding="basicHttpsBinding" bindingConfiguration="soapSecureBindingConfig" contract="Cmp.MySoft.BL.WCF.MySoftInterface" />
<endpoint name="MySoftTest" address="http://localhost:49957/MySoft.svc" binding="basicHttpBinding" bindingConfiguration="soapBindingConfig" contract="Cmp.MySoft.BL.WCF.MySoftInterface" />
</client>
<!-- Services -->
<services>
<service name="Cmp.MySoft.BL.NeOthe.NeOtheWrapper">
<endpoint name="rest" address="rest" behaviorConfiguration="restEndpointBehaviour" binding="webHttpBinding" bindingConfiguration="restBindingConfig" contract="Cmp.MySoft.BL.NeOthe.INeOtheWrapper"/>
<endpoint name="restSecure" address="rest" behaviorConfiguration="restEndpointBehaviour" binding="webHttpBinding" bindingConfiguration="restSecureBindingConfig" contract="Cmp.MySoft.BL.NeOthe.INeOtheWrapper"/>
<endpoint name="mex" address="mex" behaviorConfiguration="" binding="mexHttpBinding" bindingConfiguration="mexBindingConfig" contract="Cmp.MySoft.BL.NeOthe.INeOtheWrapper"/>
<endpoint name="mexSecure" address="mex" behaviorConfiguration="" binding="mexHttpsBinding" bindingConfiguration="mexSecureBindingConfig" contract="Cmp.MySoft.BL.NeOthe.INeOtheWrapper"/>
<endpoint name="soap" address="soap" behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="soapBindingConfig" contract="Cmp.MySoft.BL.NeOthe.INeOtheWrapper"/>
<endpoint name="soapSecure" address="soap" behaviorConfiguration="" binding="basicHttpsBinding" bindingConfiguration="soapSecureBindingConfig" contract="Cmp.MySoft.BL.NeOthe.INeOtheWrapper"/>
</service>
</services>
<!-- Binding Configurations -->
<bindings>
<webHttpBinding>
<binding name="restBindingConfig">
<security mode="None"/>
</binding>
<binding name="restSecureBindingConfig">
<security mode="Transport"/>
</binding>
</webHttpBinding>
<mexHttpBinding>
<binding name="mexBindingConfig"/>
</mexHttpBinding>
<mexHttpsBinding>
<binding name="mexSecureBindingConfig"/>
</mexHttpsBinding>
<basicHttpsBinding>
<binding name="soapSecureBindingConfig">
<security mode="Transport"/>
</binding>
</basicHttpsBinding>
<basicHttpBinding>
<binding name="soapBindingConfig">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<!-- Behaviour Configurations -->
<behaviors>
<endpointBehaviors>
<behavior name="restEndpointBehaviour">
<webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" faultExceptionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<!-- Hosting Environment Settings -->
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
据编译,运行,如果我浏览到的http:// MYPC:12345 /包装/ REST /帮助
我得到的自动生成的ASP.NET REST帮助页面。
It compiles, runs and if I browse to http://mypc:12345/wrap/rest/help
I get the auto generated ASP.NET REST help page.
但是,如果我去的http:// MYPC:12345 /包装/ SOAP /
我得到400错误的请求
But, if I go to http://mypc:12345/wrap/soap/
I get 400 Bad Request.
我不能后缀以?WSDL来获取WSDL,或通过链接直接SvcUtil工具(肥皂+ XML不是预期)
I can't suffix that with ?wsdl to get the wsdl, or pass the url to svcutil (soap+xml not expected)
我希望在.SVC SOAP占位符页面将显示,同/帮助做休息。
I was hoping the .SVC SOAP place holder page would appear, same as /help does for REST.
如果我浏览到.svc文件(这是在同一水平/套),工程和SOAP服务工作一样,元数据的发布。
If I browse to the .svc file (it's at the same level as /wrap) that works and the soap service works, as does meta data publishing.
我使用了错误的URL或者是我的配置错了?
Am I using the wrong URL or is my configuration wrong?
推荐答案
如果您正在使用WCF 4.0或更高版本,可以使用文件少激活。添加像下面到config文件:
If you're using WCF 4.0 or later, you can use "file-less" activation. Add something like the following to config your file:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="Soap.svc"
service="Cmp.MySoft.BL.NeOthe.NeOtheWrapper" />
</serviceActivations>
</serviceHostingEnvironment>
这可以让你主持一个WCF服务,没有物理.svc文件。在 relativeAddress
是相对于站点的基地址,你需要创建IIS应用程序像往常一样。
This allows you to host a WCF service without a physical .svc file. The relativeAddress
is relative to the base address of the site, and you'll need to create the IIS application as usual.
请参见开发人员的介绍了Windows Communication Foundation的4 了解更多信息。
这篇关于我如何可以承载一个WCF服务,而不在IIS中SVC文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!