1

我有一个在不同客户端上运行的 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;
            }

        }
    }
}

}

应用程序配置

<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>
4

0 回答 0