我必须做的事情已经完成:
将WCF服务添加到现有的mvc Web应用程序。在某个文件夹ex:/Service/Service1.svc
将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();
}
}
和网络配置:
<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" />
当我在IIS上浏览服务时,它显示未找到错误404。
谢谢!
答案 0 :(得分:2)
根据您的托管方式,很可能端点地址不正确/匹配。
只需将端点地址更改为空字符串。
<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>
此外,您已将此配置为https(传输安全性),因此请确保您使用的是https网址。对于初始测试,我建议首先删除安全性,然后使用基本绑定。一旦它工作,然后安全测试。