休息服务的 system.servicemodel endpoint.address 元素的解释

发布于 2024-10-11 22:34:23 字数 2496 浏览 7 评论 0原文

我有一个 WCF 休息网络服务。它运行良好。我想了解端点元素中可用的不同配置值。

特别是,我试图理解地址元素的用途。更改该值似乎并没有改变我处理该服务的方式。为此,我从 Visual Studio 2010 和 cassini 运行该服务。端口号设置为 888。

地址设置为空字符串我得到... http://localhost:888/restDataService.svc/hello 将返回“hello world”。

将地址设置为“localhost”我得到... http://localhost:888/restDataService.svc/hello 将返回“hello world”。

地址设置为“pox”时我得到...... http://localhost:888/restDataService.svc/hello 将返回“hello world”。

我在地址字段中设置什么值并不重要。它不会影响网址。我唯一的解释是非 REST 服务的价值更大。

<system.serviceModel>
  <services>
    <service behaviorConfiguration="MobileService2.DataServiceBehaviour" name="MobileService2.DataService">

      <endpoint address="pox" binding="webHttpBinding" contract="MobileService2.IRestDataService" behaviorConfiguration="webHttp">
      </endpoint>

      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webHttp">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="MobileService2.DataServiceBehaviour" >
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

我还有以下服务合同

    [ServiceContract]
    public interface IRestDataService
    {
        [OperationContract]
        [WebGet(UriTemplate = "hello")]
        string Hello();
    }

并在 .svc

<%@ ServiceHost Language="C#" Debug="true" 
            Service="MobileService2.RestDataService" 
            Factory="System.ServiceModel.Activation.WebServiceHostFactory"
            CodeBehind="RestDataService.svc.cs" %>

和“代码隐藏”中

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RestDataService : IRestDataService
{
    public string Hello()
    {
        return "hello";
    }
}

I have a WCF rest webservice. It is working fine. I am wanting to understand the different configuration values available within the endpoint element.

In particular, I'm trying to understand the purpose of the address element. Changing the value doesn't seem to change how I can address the service. For this, I'm running the service from visual studio 2010 and cassini. the port number is set to 888.

with address set to an empty string i get...
http://localhost:888/restDataService.svc/hello will return "hello world".

with address set to "localhost" i get...
http://localhost:888/restDataService.svc/hello will return "hello world".

with address set to "pox" i get...
http://localhost:888/restDataService.svc/hello will return "hello world".

It doesn't matter what value I set into the address field. It doesn't impact the url. My only explanation that I have is that the value is more for non-REST services.

<system.serviceModel>
  <services>
    <service behaviorConfiguration="MobileService2.DataServiceBehaviour" name="MobileService2.DataService">

      <endpoint address="pox" binding="webHttpBinding" contract="MobileService2.IRestDataService" behaviorConfiguration="webHttp">
      </endpoint>

      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="webHttp">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="MobileService2.DataServiceBehaviour" >
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

I also have the following service contract

    [ServiceContract]
    public interface IRestDataService
    {
        [OperationContract]
        [WebGet(UriTemplate = "hello")]
        string Hello();
    }

And in the .svc

<%@ ServiceHost Language="C#" Debug="true" 
            Service="MobileService2.RestDataService" 
            Factory="System.ServiceModel.Activation.WebServiceHostFactory"
            CodeBehind="RestDataService.svc.cs" %>

And the 'code-behind'

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RestDataService : IRestDataService
{
    public string Hello()
    {
        return "hello";
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

全部不再 2024-10-18 22:34:23

您还可以显示您的配置的服务元素吗?我认为您的配置未使用或者您正在访问应用程序的其他实例(您是否将 Cassini 配置为使用端口 80?),因为您的第二个和第三个测试应该返回 HTTP 404 Resource not found。

测试的正确地址是:

  1. http://localhost/restDataService.svc/hello
  2. http://localhost/restDataService.svc/localhost/hello
  3. http://localhost/restDataService.svc/pox/hello

检查服务元素中的名称是否与服务类型的名称(包括命名空间)完全相同用于 .svc 标记中的 ServiceHost 指令。

Can you also show service element of your configuration? I think that your configuration is not used or you are accessing other instance of the application (did you configure Cassini to use port 80?) because your second and third test should return HTTP 404 Resource not found.

Correct addresses for your tests are:

  1. http://localhost/restDataService.svc/hello
  2. http://localhost/restDataService.svc/localhost/hello
  3. http://localhost/restDataService.svc/pox/hello

Check that your name in service element is exactly the same as name of service type (including namespaces) as used in ServiceHost directive in .svc markup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文