我的问题围绕着一个响应JSONP的IIS WCF REST服务。我使用了这个解决方案中的类:http://msdn.microsoft.com/en-us/library/cc716898.aspx,并将它们添加到我的项目中。在我的开发工作站上,使用httpTransport进行模拟时一切都很顺利,但当我尝试转移到开发服务器时,遇到了一些安全问题。我使用以下配置和App Pool身份用户解决了这些问题,并且还为NTLM认证配置了IIS metabase文件(我们正在使用IIS 6但很快会是IIS 7,需要在两个版本上工作),因为我没有权限创建SPN。我相信当前的配置解决了我的安全问题,但在此过程中,我的JSONP响应被降级为普通的JSON,这就是问题所在。下面是相关的配置:
<services>
<service name="IS.Core.Infrastructure.RESTRouter.Transactions" behaviorConfiguration="">
<endpoint address="" behaviorConfiguration="webHttp" binding="customBinding"
bindingConfiguration="jsonpBinding" contract="IS.Core.Infrastructure.RESTRouter.ITransactions">
</endpoint>
</service>
<service name="IS.Core.Infrastructure.RESTRouter.Queue" behaviorConfiguration="">
<endpoint address="" behaviorConfiguration="webHttp" binding="customBinding"
bindingConfiguration="jsonpBinding" contract="IS.Core.Infrastructure.RESTRouter.IQueue" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="jsonpBinding">
<jsonpMessageEncoding />
<httpsTransport
manualAddressing="true"
authenticationScheme="Ntlm" />
</binding>
</customBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="jsonpMessageEncoding"
type="IS.Core.Infrastructure.RESTRouter.JsonpBindingExtension, RESTRouter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
以下是接口方法定义之一:
[OperationContract]
[WebGet(UriTemplate = "{ModelPath}/{ObjectTypeName}?callback={callback}", ResponseFormat = WebMessageFormat.Json)]
[JSONPBehavior(callback = "callback")]
JSONPXml NewObject(string ModelPath, string ObjectTypeName, string callback);
这是它的实现代码:
[OperationBehavior(Impersonation = ImpersonationOption.Allowed)]
public JSONPXml NewObject(string ModelPath, string ObjectTypeName, string callback) {
int val = getEmployeeIdByNTUsername(OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name);
JSONPXml jsp = null;
EntityPluginReflectorClient client = null;
try {
client = new EntityPluginReflectorClient();
string output = client.NewObject(ModelPath, ObjectTypeName);
jsp = new JSONPXml() { xml = output };
} catch (Exception e) {
InfrastructureLog.WriteException(this, "NewObject", e);
jsp = getExceptionResponse(e);
}
finally {
client.Close();
}
return (jsp);
}
这里是数据契约:
[DataContract()]
public class JSONPXml {
public JSONPXml() { }
[DataMember]
public string xml;
}
如果需要更多信息,请告诉我,感谢您对此进行了解。