如何 return 来自 WCP 请求的 JsonP?

how to return JsonP from a WCP request?

我想构建一个 WCF 服务,它将 return JsonP 请求。我想要它return以下,

jsonpCallback({"fileNames":"IDR023.T.201705201412.png, IDR023.T.201705201418.png"});

所以我创建了以下 WCF 服务

IBOM.cs

  [ServiceContract]
    public interface IBOM
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json)]
        string GetData();
    }

BOM.cs

 public class BOM : IBOM
    {

        public string GetData()
        {
            return "jsonpCallback({\"fileNames\":\"IDR023.T.201705201412.png, IDR023.T.201705201418.png\"});";


        }
    }

网络配置

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="BomService.BOM" behaviorConfiguration="ServiceBehaviour">
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="webHttpBinding" contract="BomService.IBOM" behaviorConfiguration="web">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
        </endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

但我回来了

"jsonpCallback({\"文件名\":\"IDR023.T.201705201412.png, IDR023.T.201705201418.png\"});"

我正在 return 一个字符串并尝试将其设置为 return 我需要的。这是 JSONP 的最佳方式吗?或者有没有更好的方法来实现我所需要的

谢谢

对于任何感兴趣的人,我已经解决了。这是代码。

IBOM

[服务合同] public 接口 IBOM {

[OperationContract]
[WebInvoke(Method = "GET",
    ResponseFormat = WebMessageFormat.Json)]
Stream GetData();

}

物料清单

public class BOM : IBOM
    {
      public Stream GetData()
        {


            string jsCode = "jsonpCallback" + "({\Test:\"" + fileNames +   "\"});";
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/javascript";
            return new MemoryStream(Encoding.UTF8.GetBytes(jsCode));

        }