我的 WCF JSONP Web 服务遇到了一个“有趣的”错误。它是我唯一拥有的,它只公开一种方法。如果我在内部通过 Web 浏览器访问我的服务,它会弹出一条消息,实际上 MEX 未启用(真)。如果我从我们的网络外部点击它(就像你会,除非你在我公司的一台机器上)它只是坐在那里,最后超时。URL 是: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