[英]Host WCF to existing MVC Web site
Things i have to do and already done : 我必须做且已经完成的事情:
Add WCF service to an existing mvc web app. 将WCF服务添加到现有的mvc Web应用程序。 under some folder
ex:/Service/Service1.svc
在某些文件夹下,
ex:/Service/Service1.svc
Host the MVC site to IIS, completely functioning site tested. 将MVC站点托管到IIS,经过完全测试的站点正常运行。
namespace WebApplication3.Service { public class Service1 : IService1 { public string DoWork() { return "some string"; } } } namespace WebApplication3.Service { [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(Method = "GET")] string DoWork(); } }
and the web config : 和网络配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="transportsecurity">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior">
<endpoint address="http://localhost/testsite/Service/Service1.svc" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mybehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
when i browse the service on IIS it shows not found error 404. 当我在IIS上浏览服务时,显示未找到错误404。
Thanks! 谢谢!
Most likely the endpoint address is not correct/matching based on how you are hosting. 根据您的托管方式,端点地址很可能不正确/不匹配。
Just change the endpoint address to empty string. 只需将端点地址更改为空字符串即可。
<services>
<service name="WebApplication3.Service.Service1" behaviorConfiguration="mybehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="transportsecurity" contract="WebApplication3.Service.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
Also, you have configured this to be https (transport security), so make sure you are using https url. 另外,您已将其配置为https(传输安全性),因此请确保您使用的是https url。 For initial testing I would suggest first remove the security and have just work with basic binding.
对于初始测试,我建议首先删除安全性,并使用基本绑定。 Once it working, then test with security.
一旦工作,然后进行安全性测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.