自定义ServiceHostFactory仅返回HTTPS BaseAddress [英] Custom ServiceHostFactory Only Returns HTTPS BaseAddress
问题描述
由于我的托管服务提供商使用共享的托管环境(GoDaddy),因此我需要创建一个自定义ServiceHostFactory对象,该对象将覆盖CreateServiceHost函数(如
Since my hosting provider uses a shared hosting environment (GoDaddy), I need to create a custom ServiceHostFactory object that overrides the CreateServiceHost function (as described here). Before trying to make the WCF service work at GoDaddy, I am testing it locally on IIS v5 (standard install that comes with WinXP Professional with .NET v3.5). The problem I have is that when IIS calls my override function CreateServiceHost, it only returns a HTTPS baseAddress. I need just a plain HTTP baseAddress and don't understand why HTTPS is being returned by IIS. I only have the default website configured on port 80/TCP. Below is the code:
后端代码文件(.cs)
Backend code file (.cs)
命名空间 .服务 |
{ |
[ServiceContract] |
public 界面 iPhoneHomeService |
.{ |
[OperationContract] |
无效 PostIp( 字符串 id); |
public 类 iPhoneHomeService:iPhoneHomeService |
.{ |
public 无效 PostIp( string id) |
.{ |
//完成工作 > |
public class GodaddyServiceFactory:ServiceHostFactory |
.{ |
受保护的 替代 ServiceHost CreateServiceHost(Type serviceType,Uri [] baseAddresses) |
.{ |
如果 (baseAddresses.Length> 1) |
返回 new 服务主机(serviceType,baseAddresses [1]); |
其他 |
返回 new ServiceHost(serviceType,baseAddresses [0]); |
} |
} |
namespace Concolor.Net.Services |
{ |
[ServiceContract] |
public interface IPhoneHomeService |
{ |
[OperationContract] |
void PostIp(string id); |
} |
public class PhoneHomeService : IPhoneHomeService |
{ |
public void PostIp(string id) |
{ |
//Do work |
} |
} |
public class GodaddyServiceFactory : ServiceHostFactory |
{ |
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) |
{ |
if (baseAddresses.Length > 1) |
return new ServiceHost(serviceType, baseAddresses[1]); |
else |
return new ServiceHost(serviceType, baseAddresses[0]); |
} |
} |
} |
推荐答案
我认为你
为什么不为您的< service>添加一些基址?标签:
I think you're missing a base address list for that code snippet you've got.
Why not add some base addresses into your <service> tag:
<service ...>
<endpoint ... />
<host>
<baseAddresses>
<add baseAddress="http://myhost/service1.svc" />
<!-- comment this one out when you want http: -->
<add baseAddress="https://myhost/service1.svc" />
</baseAddresses>
</host>
</service>
这篇关于自定义ServiceHostFactory仅返回HTTPS BaseAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!