有有自定义的WCF友好的URL没有IIS的方法吗? [英] Is there a way to have custom defined friendly URLs with WCF without IIS?

查看:135
本文介绍了有有自定义的WCF友好的URL没有IIS的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有有自定义的WCF友好的URL没有IIS的方式?

在特定的我期待通过托管在我自己的Windows服务的app.config中做这样的事情:

  [WebGet(UriTemplate =富/ {ID})]
公共字符串的getFoo(串号)
{
   ...
}
 

解决方案

当然可以 - 主机这是你自己的NT服务里面,在你的的app.config ,定义HTTP基址。您在服务合同中所定义的URI模板将关闭该基地地址:

 <服务>
   <服务名称=YourNamespace.YourServiceClass>
      <主机>
         < baseAddresses>
             <新增baseAddress =HTTP:// YourServer:9091 /服务//>
         < / baseAddresses>
      < /主机>
      <端点地址=
                绑定=的WebHttpBinding
                合同=YourNamespace.IYourService/>
   < /服务>
< /服务>
 

那么你的URI模板将被添加到该基址的,所以在这种情况下,您的getFoo 的方法是调用为:

 的http:// YourServer:9091 /服务/富/ 42
 

更新:我只是重新创建这个在这里,问题是这样的:你的URI模板定义了一个名为 {ID} 参数,但应用这种方法,URI模板不具有名为 ID 的任何参数,在它的参数列表:

  [WebGet(UriTemplate =富/ {ID})]
公共字符串的getFoo(字符串fooID)
 

您需要确保这些东西搭配!在给定的URI的模板,你需要改变你的方法声明为:

  [WebGet(UriTemplate =富/ {ID})]
公共字符串的getFoo(串号)
 

(见参数 - 它的名字,现在 ID ),然后你应该罚款 - 至少它工作得很好,我

Is there a way to have custom defined friendly URLs with WCF without IIS?

In particular I'm looking to do something like this via an app.config hosted in my own Windows service:

[WebGet(UriTemplate = "foo/{id}")]
public string GetFoo(string id)
{
   ...
}

解决方案

Yes sure - host this inside your own NT Service, and in your app.config, define a http base address. The URI templates you define in your service contract will be off that base address:

<services>
   <service name="YourNamespace.YourServiceClass">
      <host>
         <baseAddresses>
             <add baseAddress="http://YourServer:9091/Services/" />
         </baseAddresses>
      </host>
      <endpoint address="" 
                binding="webHttpBinding" 
                contract="YourNamespace.IYourService" />    
   </service>
</services>

Then your URI template will be added to this base address, so in that case, you GetFoo method would be callable at:

http://YourServer:9091/Services/foo/42

Update: I just recreated this here, and the problem is this: your URI template defines a parameter called {id}, but the method you apply this URI template to doesn't have any parameter called id in it's parameter list:

[WebGet(UriTemplate = "foo/{id}")]
public string GetFoo(string fooID)

You need to make sure those things match! With the given URI template, you need to change your method declaration to:

[WebGet(UriTemplate = "foo/{id}")]
public string GetFoo(string id)

(see the parameter - it's name is now id) and then you should be fine - at least it works just fine for me.

这篇关于有有自定义的WCF友好的URL没有IIS的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆