jQuery ajax无法调用WCF服务

时间:2013-10-03 12:47:00

标签: jquery asp.net ajax wcf service

我在不同的客户端上运行Windows服务。 我的服务器上有一个Web应用程序,在登录页面上通过Jquery ajax调用来调用客户端上的Windows服务。

当调用服务时一切正常,我有一个服务日志,向我展示它所做的所有操作,但是ajax调用总是失败! ajax调用永远不会成功,但我知道服务很好。

我不知道有哪些安全问题?

这是jquery调用:

var Type;
var Url;
var Data = "";
var ContentType;
var DataType;
var ProcessData;

Type = "GET";

Url = "http://localhost:8000/printTicket_test?par=hello"; 
alert(Url);
ContentType = "application/json; charset=utf-8";
DataType = "jsonp";
ProcessData = true;
jq.support.cors = true;
jq.ajaxSetup({ cache: false });

jq.ajax({
    url: Url, // Location of the service
    type: Type, //GET or POST or PUT or DELETE verb
    //async: false,
    data: Data, //Data sent to server
    contentType: ContentType, // content type sent to server
    dataType: DataType, //Expected data format from server
    processdata: ProcessData, //True or False
    success: function (msg) {//On Successfull service call
        // ServiceSucceeded(msg);
        alert("test");
        alert(msg);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        alert("test_1" + textStatus);
        alert("test_2" + errorThrown);
        alert("test_3 " + jqXHR.responseText);
    }
    //error: ServiceFailed// When Service call fails
});

这是我的服务:

namespace PrintService{

[ServiceContract]
public interface IHelloWorldService
{  

   [OperationContract]
    [WebInvoke(Method = "GET",
    ResponseFormat = WebMessageFormat.Json)]
    string printTicket_test(string par);


    }
    [AspNetCompatibilityRequirements(RequirementsMode
    = AspNetCompatibilityRequirementsMode.Allowed)]
    public class HelloWorldService : IHelloWorldService
    {

        private static readonly log4net.ILog m_LogFile = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

         public string printTicket_test(string par)
        {
            try
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
                {
                    return true;
                };

                m_LogFile.Debug("printTicket_test");
                m_LogFile.Debug("Call test PrintTicket with parameter par=" + par);
                return par;
            }
            catch (Exception ex)
            {
                m_LogFile.Error(ex.Message);
                return ex.Message;
            }

        }
    }
}

}

的app.config

<startup>


<supportedRuntime version="v2.0.50727"/></startup>

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="EndpBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="ServiceBehavior" name="HelloWorldService">
    <endpoint address="" binding="webHttpBinding" contract="IHelloWorldService" behaviorConfiguration="EndpBehavior"/>
  </service>
</services>
</system.serviceModel>

0 个答案:

没有答案