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

Zac*_*ter 4 c# rest wcf soap

您好,谢谢您的阅读.

我正在尝试获取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!";
    }
}
Run Code Online (Sandbox Code Playgroud)

而现在,配置中包含了我认为需要进行的更改(我不确定是否需要保留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>
Run Code Online (Sandbox Code Playgroud)

Global.asax.cs文件一个人留下.

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

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

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

谢谢,

扎卡里卡特

mar*_*c_s 7

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

  • 我用过你的服务类 - 没有变化
  • 我用你的RegisterRoutes电话global.asax.cs

当我从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
Run Code Online (Sandbox Code Playgroud)

相同的URL是否适合您?

更新:这是我的配置 - 我可以http://localhost:3131/Service1/HelloWorld使用REST 连接到浏览器,我可以连接到http://localhost:3131/Service1/soapWCF测试客户端进行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>
Run Code Online (Sandbox Code Playgroud)