0

我在stackoverflow中看到了很多答案,但它们并没有帮助我。我有一个 wcf 服务,当我运行它时,它会在浏览器上显示有效的输出。当我在 jquery 客户端中使用它时,它没有提供任何输出。我想使用该 wcf 服务来绘制以下图表我的配置文件

<system.serviceModel>
    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" 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.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfService1.Service1Behavior">
          <!-- 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>
  </system.serviceModel>

以下是我的cs代码

[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate="empdetials")]
        List<employee> empdetials();

    }

以下是我的客户端代码

$(document).ready(function () {
            var sourcee = {};

            $.ajax({
                cache: false,
                async: true,
                type: "GET",
                url: "http://localhost:1331/Service1.svc/empdetials",

                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert(data.d);
                    sourcee = $.parseJSON(data.d);
                    alert(sourcee);
                },
                error: fnerrorcallback
            });
4

1 回答 1

0

只需将您的服务配置为跨域:http: //lucbei.wordpress.com/2010/09/04/cross-domain-wcf-restful-with-jsonp-2/

于 2013-11-04T07:10:33.617 回答