2011-04-13 84 views
4

您好,非常感谢您的阅读。IIS 7.5中的REST/SOAP端点的WCF 4服务

我想获得一个服务托管在IIS 7.5,有多个端点公开。

我有一种感觉问题在于我的web.config,但我会在这里发布我的服务代码。没有接口文件,因为我使用WCF 4的新功能,也没有.svc文件。

根据我的理解,所有的路由都使用RouteTable功能在Global.asax.cs中处理。

无论如何,到代码/配置 -

[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
// NOTE: If the service is renamed, remember to update the global.asax.cs file 
public class Service1 
{ 
    // TODO: Implement the collection resource that will contain the SampleItem instances 

    [WebGet(UriTemplate = "HelloWorld")] 
    public string HelloWorld() 
    { 
     // TODO: Replace the current implementation to return a collection of SampleItem instances 
     return "Hello World!"; 
    } 
} 

而现在,配置和我认为需要作出(我不知道如果我需要保持standardEndpoints阻塞的变化,但有或没有它,我仍然得到错误信息 -

<services> 
    <service name="AiSynthDocSvc.Service1" behaviorConfiguration="HttpGetMetadata"> 
    <endpoint name="rest" 
       address="" 
       binding="webHttpBinding" 
       contract="AiSynthDocSvc.Service1" 
       behaviorConfiguration="REST" /> 
    <endpoint name="soap" 
       address="soap" 
       binding="basicHttpBinding" 
       contract="AiSynthDocSvc.Service1" /> 
    <endpoint name="mex" 
       address="mex" 
       binding="mexHttpBinding" 
       contract="IMetadataExchange" /> 
    </service> 
</services>  

<behaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="HttpGetMetadata"> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<standardEndpoints> 
    <webHttpEndpoint> 
    <!-- 
     Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
     via the attributes on the <standardEndpoint> element below 
    --> 
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
    </webHttpEndpoint> 
</standardEndpoints> 

的的Global.asax.cs文件被单独留在家中

再次我敢肯定它是与我的配置。 Ť当我尝试访问任何定义的端点时,他遇到的错误是 -

''处的端点没有与无消息版本的绑定。 'System.ServiceModel.Description.WebHttpBehavior'仅用于WebHttpBinding或类似的绑定。

任何人对此有任何意见?

感谢,

扎卡里·卡特

+0

你用什么URL来访问你的服务? – 2011-04-13 15:49:45

+0

另外:你说你没有* .svc文件 - 你的服务如何激活呢?您可能需要* .svc文件,或者您需要在配置文件中添加标签。 – 2011-04-13 15:50:51

+0

该服务被部署到端口80上的默认网站,因此它只是 - http:// localhost/WebApp/ServiceName来访问它。另外,在没有.svc文件的情况下创建服务的功能是.NET 4.0中的一项新功能。不是击中svc文件,而是添加了一个新类,以将请求正确路由到相应的服务。 – 2011-04-13 16:58:59

回答

7

OK,我试图复制你的东西 - 就像我的一个魅力:-)

  • 我用你的服务类 - 没有改变
  • 我用你的RegisterRoutes致电global.asax.cs

当我在Visual Studio中启动Web应用程序时,我得到了卡西尼(内置Web服务器)http://localhost:3131/ - 这可能会对您的情况有所警惕。现在

,我可以很容易地与另一个浏览器窗口导航那里,我得到这个URL简单地回答:

http://localhost:3131/Service1/HelloWorld 
+--------------------+ 
from Cassini 
        +--------+ 
        name (first param) in ServiceRoute registration 
           +-----------+ 
           from your URI template on the WebGet attribute 

为你做同样的网址工作?

更新:这里是我的配置 - 我可以使用REST连接到http://localhost:3131/Service1/HelloWorld在浏览器中,我可以与WCF测试客户端连接到http://localhost:3131/Service1/soap做出SOAP调用(我Service1生活在RestWebApp命名空间 - 这样我服务和合同的名称是比你不同的一点点 - 但除此之外,我认为这是等同于你自己的配置):

<system.serviceModel> 
    <serviceHostingEnvironment  
     aspNetCompatibilityEnabled="true" /> 
    <services> 
     <service name="RestWebApp.Service1" behaviorConfiguration="Meta"> 
     <endpoint name="rest" 
        address="" 
        binding="webHttpBinding" 
        contract="RestWebApp.Service1" 
        behaviorConfiguration="REST" /> 
     <endpoint name="SOAP" 
      address="soap" 
      binding="basicHttpBinding" 
      contract="RestWebApp.Service1" /> 
     <endpoint name="mex" 
      address="mex" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="REST"> 
      <webHttp/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="Meta"> 
      <serviceMetadata httpGetEnabled="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <standardEndpoints> 
     <webHttpEndpoint> 
     <!-- 
     Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
     via the attributes on the <standardEndpoint> element below 
     --> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 
     </webHttpEndpoint> 
    </standardEndpoints> 
    </system.serviceModel> 
+0

马克,它绝对如果我离开配置文件。我的问题是,当我尝试公开一个配置为使用basicHttpBinding的附加端点时,原始的REST端点会伸出,并且新发现的端点也无法找到。 – 2011-04-13 19:25:13

+0

我SOAP端点的样子 - <端点名称= “肥皂” 地址= “肥皂” 绑定= “basicHttpBinding的” 合同= “AiSynthDocSvc.Service1”/> 但导航到http://本地主机:80 /服务1/soap产生以下错误消息 - 'http://vm-scctest.amcad.com/AiSynthDocSvc/Service1/soap'上的端点没有与无消息版本的绑定。 'System.ServiceModel.Description.WebHttpBehavior'仅用于WebHttpBinding或类似的绑定。 – 2011-04-13 19:34:19

+0

我再次想到这与服务有一个行为配置设置为webHttpBinding和端点行为配置设置为使用basicHttpBinding。 – 2011-04-13 19:34:54

0

感谢这一点,对我帮助很大。

我的情况是,我有一个默认行为配置,其中包含webHttp。给它的名称=“REST”并设置我的webHttpBinding端点behaviourConfiguration =“REST”我没有进一步的错误。

<system.serviceModel> 
<bindings> 
    <customBinding> 
    <binding name="CustomBinding_IMobileService"> 
     <binaryMessageEncoding /> 
     <httpTransport /> 
    </binding> 
    </customBinding> 
</bindings> 
<client> 
    <endpoint address="http://localhost:6862/silverlight/services/MobileService.svc" 
    binding="customBinding" bindingConfiguration="CustomBinding_IMobileService" 
    contract="AlchemyMobileService.IMobileService" name="CustomBinding_IMobileService" /> 
</client> 
<services> 
    <service name="MobileService.Alchemy"> 
    <endpoint address="http://localhost:8732/mobileservice" binding="webHttpBinding" contract="MobileService.IAlchemy" behaviorConfiguration="REST"> 
    </endpoint> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceDebug includeExceptionDetailInFaults="True" /> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
</behaviors>