1

I have a windows service running on different clients. I have a web application on my server that on login page call windows service on client by Jquery ajax call.

When service is called all work fine, I have a service log that show me all the operation that it does, but ajax call always fail! The ajax call never go in success method, but I know that service is called fine.

There are security problems that I don't know ?

this is jquery call :

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
});

this is my service :

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>
jwaliszko
  • 16,942
  • 22
  • 92
  • 158
tulkas85
  • 1,103
  • 1
  • 17
  • 43
  • Is the webservice url the same domain as where the page is coming from? – LondonAppDev Oct 03 '13 at 12:49
  • What is the actual HTTP response from the service? – David Oct 03 '13 at 12:50
  • IIS and web application run on my machine, and service is installed on the same machine. In a real scenario I have a public web server and a browser client that call login page with ajax code inside, and ajax code call the service on client machine. So I think that service is consumed always by localhost – tulkas85 Oct 03 '13 at 13:00
  • Go through this answer please, I believe it will help you to track the problem: http://stackoverflow.com/a/17492649/270315. – jwaliszko Oct 03 '13 at 13:06
  • CrossDomainScriptAccessEnabled attribute could be the solution ? unfortunately I can't install framework 4 on client machines, they must have framework 3.5. and CrossDomainScriptAccessEnabled not work on 3.5 – tulkas85 Oct 03 '13 at 13:10
  • For 3.5 check this: http://msdn.microsoft.com/en-us/library/cc716898%28VS.90%29.aspx – jwaliszko Oct 03 '13 at 13:15
  • For my purpose I no need json or jsonp for sending data, I must only receive a string from service that tell me the status... – tulkas85 Oct 03 '13 at 13:21
  • *For my purpose I no need json or jsonp for sending data, ...* If that is true, why do you use jsonp? – jwaliszko Oct 03 '13 at 15:21

0 Answers0