WCF自定义JSONP绑定和httpsTransport

13 c# rest wcf iis-6

我的问题围绕用于响应JSONP的IIS的WCF REST服务.我参加了这个解决方案中的课程:http://msdn.microsoft.com/en-us/library/cc716898.aspx并将它们添加到我的.使用httpTransport模拟我的开发人员工作站上的工作正常,但当我尝试升级到开发服务器时遇到了一些安全问题.使用下面的配置和App Pool身份用户解决了这些问题.我还配置IIS元数据库文件仅用于NTLM身份验证(我们正在使用IIS 6,但很快就会是IIS 7,需要同时使用它们),因为我无权创建SPN.我相信当前的配置解决了我的安全问题,但在此过程中我的JSONP响应被降级为regualar 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>
Run Code Online (Sandbox Code Playgroud)

这是接口方法定义之一:

    [OperationContract]
    [WebGet(UriTemplate = "{ModelPath}/{ObjectTypeName}?callback={callback}", ResponseFormat = WebMessageFormat.Json)]
    [JSONPBehavior(callback = "callback")]
    JSONPXml NewObject(string ModelPath, string ObjectTypeName, string callback);
Run Code Online (Sandbox Code Playgroud)

这是它的实现:

    [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);
    }
Run Code Online (Sandbox Code Playgroud)

这是数据合同:

[DataContract()]
public class JSONPXml {
    public JSONPXml() { }
    [DataMember]
    public string xml;
}
Run Code Online (Sandbox Code Playgroud)

如果需要更多信息,请告诉我,并感谢您对此进行调查.

Mat*_*ser 0

这看起来似乎是一个显而易见的问题,但是您是否检查过您是否仍在开发服务器中传递“回调”查询参数?

查看 JSONPEncoder 源代码,即使尚未收到“callback”参数,它似乎仍会向响应写入 JSON 消息。它只是不会格式化 JavaScript 方法包装器。