C# WCF 在企业防火墙内部工作,但在外部不起作用
我的 WCF JSONP Web 服务遇到了一个“有趣”的错误。这是我唯一拥有的,它只公开一种方法。如果我通过网络浏览器内部访问我的服务,它会弹出一条消息,表明 MEX 实际上未启用(true)。如果我从我们的网络外部点击它(就像你一样,除非你在我公司的一台机器上),它就会停留并最终超时。网址为:http://demo.rivworks.com/services/Negotiate.svc。关于可能导致这种行为的任何想法?
这是 web.config:
<!-- WCF configuration -->
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="JsonpServiceBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="RivWorks.Web.Service.NegotiateService">
<endpoint address=""
binding="customBinding"
bindingConfiguration="jsonpBinding"
behaviorConfiguration="JsonpServiceBehavior"
contract="RivWorks.Web.Service.INegotiateService" />
</service>
</services>
<extensions>
<bindingElementExtensions>
<add name="jsonpMessageEncoding" type="RivWorks.Web.Service.JSONPBindingExtension, RivWorks.Web.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="jsonpBinding" >
<jsonpMessageEncoding />
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
</bindings>
</system.serviceModel>
</configuration>
这是代码:
namespace RivWorks.Web.Service
{
//----------------------------------------------------------------------------------------------------------//
// Data class //
//----------------------------------------------------------------------------------------------------------//
[DataContract(Name = "NegotiateSetup", Namespace = "http://rivworks.com/DataContracts/2009/01/15")]
public class NegotiateSetup : INegotiationInitialize
{
#region Declarations
...
#endregion
#region INegotiationInitialize Members
...
#endregion
}
//----------------------------------------------------------------------------------------------------------//
// Service Implementation //
//----------------------------------------------------------------------------------------------------------//
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NegotiateService : INegotiateService
{
public NegotiateService() { }
public INegotiationInitialize GetSetup(string method, string jsonInput)
{
...
return resultSet;
}
}
}
我在这里追求几件事:
- 为什么我不能从本地网络外部访问它?
- 如何让 MEX 正常工作
注意:我正在使用此处找到的 JSONP 类: http://msdn.microsoft.com/en-us/library/cc716898.aspx
I am running into an “interesting” error with my WCF JSONP web service. It is the only one I have and it only exposes one method. If I hit my service via web browser internally it pops up with a message that, effectively, MEX is not enabled (true). If I hit it from outside our network (like you would unless you were on a machine in my company) it just sits and finally times out. The URL is: http://demo.rivworks.com/services/Negotiate.svc. Any ideas as to what might be causing this behavior?
Here is the web.config:
<!-- WCF configuration -->
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="JsonpServiceBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="RivWorks.Web.Service.NegotiateService">
<endpoint address=""
binding="customBinding"
bindingConfiguration="jsonpBinding"
behaviorConfiguration="JsonpServiceBehavior"
contract="RivWorks.Web.Service.INegotiateService" />
</service>
</services>
<extensions>
<bindingElementExtensions>
<add name="jsonpMessageEncoding" type="RivWorks.Web.Service.JSONPBindingExtension, RivWorks.Web.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="jsonpBinding" >
<jsonpMessageEncoding />
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
</bindings>
</system.serviceModel>
</configuration>
Here is the code:
namespace RivWorks.Web.Service
{
//----------------------------------------------------------------------------------------------------------//
// Data class //
//----------------------------------------------------------------------------------------------------------//
[DataContract(Name = "NegotiateSetup", Namespace = "http://rivworks.com/DataContracts/2009/01/15")]
public class NegotiateSetup : INegotiationInitialize
{
#region Declarations
...
#endregion
#region INegotiationInitialize Members
...
#endregion
}
//----------------------------------------------------------------------------------------------------------//
// Service Implementation //
//----------------------------------------------------------------------------------------------------------//
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NegotiateService : INegotiateService
{
public NegotiateService() { }
public INegotiationInitialize GetSetup(string method, string jsonInput)
{
...
return resultSet;
}
}
}
I am after a couple of things here:
- Why can I NOT hit it from outside my local network?
- How can I get MEX working properly
Note: I am using the JSONP classes found here: http://msdn.microsoft.com/en-us/library/cc716898.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要启用 MEX,请在
service
标记内添加以下内容:在
behaviors
标记内添加:关于为何无法从外部访问该服务,这是否是防火墙问题?
To enable your MEX, add this inside your
service
tag:Inside your
behaviors
tag, add:About why that service isn't accessible from outside, can this be a firewall issue?