繁体   English   中英

IIS 7.5中使用REST / SOAP端点的WCF 4服务

[英]WCF 4 Service with REST/SOAP endpoints in IIS 7.5

您好,谢谢您的阅读。

我正在尝试获取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文件一个人留下。

我再次确定它与我的配置有关。 当我尝试访问任何定义的端点时,我得到的错误是 -

''的端点没有与None MessageVersion的绑定。 'System.ServiceModel.Description.WebHttpBehavior'仅适用于WebHttpBinding或类似绑定。

有人对这个有任何想法吗?

谢谢,

扎卡里卡特

好的,我试图复制你的东西 - 对我来说就像一个魅力:-)

  • 我用过你的服务类 - 没有变化
  • 我在global.asax.cs使用了RegisterRoutes调用

当我从Visual Studio中启动Web应用程序时,我得到了Cassini(内置的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

相同的URL是否适合您?

更新:这是我的配置 - 我可以使用REST连接到浏览器中的http://localhost:3131/Service1/HelloWorld ,我可以使用WCF测试客户端连接到http://localhost:3131/Service1/soap SOAP调用(我的Service1存在于RestWebApp命名空间中 - 因此我的服务和合同名称与您的不同 - 但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>

谢谢你,这对我帮助很大。

我的问题是我配置了包含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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM