如何使用Javascript使用WCF Web服务?

如何使用Javascript使用WCF Web服务?,javascript,web-services,wcf,soap,Javascript,Web Services,Wcf,Soap,我没有任何使用WCF的经验,但现在需要将WCF Web服务作为项目的一部分使用。我一直收到400个错误的请求 OPTIONS http://10.138.77.27:222/focisqmobile/Service1.svc?wsdl 400 (Bad Request) n.ajaxTransport.k.cors.a.crossDomain.send n.extend.ajax WCFJSON (anonymous function) n.Callbacks.

我没有任何使用WCF的经验,但现在需要将WCF Web服务作为项目的一部分使用。我一直收到400个错误的请求

OPTIONS http://10.138.77.27:222/focisqmobile/Service1.svc?wsdl 400 (Bad Request)
  n.ajaxTransport.k.cors.a.crossDomain.send 
  n.extend.ajax 
  WCFJSON   
  (anonymous function)  
  n.Callbacks.j 
  n.Callbacks.k.fireWith    
  n.extend.ready    
  I 
XMLHttpRequest cannot load http://10.138.77.27:222/focisqmobile/Service1.svc?wsdl. Invalid HTTP status code 400
我的AJAX代码如下所示:

function WCFJSON() {


        Data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "<s:Header>"+
        "<Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/IService1/getProduct</Action>"+
    "</s:Header>"+
        "<s:Body>" +
        "<getProduct xmlns=\"http://tempuri.org/\"/>" +
        "</s:Body>" +
        "</s:Envelope>";

        $.ajax({
            type: "POST", //GET or POST or PUT or DELETE verb
            url: "http://10.138.77.27:222/focisqmobile/Service1.svc?wsdl", // Location of the service
            data: Data, //Data sent to server
            contentType: "text/xml; charset=utf-8", // content type sent to server
            dataType: "xml", //Expected data format from server
            processData: true, //True or False
            success: ServiceSucceeded, //On Successfull service call
            error: ServiceFailed// When Service call fails
        });

    }

    function ServiceSucceeded(xml) {

        alert("Success");
        alert($.parseXML(xml));


    }

    function ServiceFailed(xhr) {
        alert("Error");
        alert($.parseXML(xhr));

    }
我使用的soap消息来自WCF测试客户端:

WCF测试客户端能够从服务器获得响应

现在,我的主要问题是:

我是否需要更改Web服务中的任何内容以使其可从Javascript使用? 我是否使用了错误的SOAP消息? 为什么WCF测试客户端能够在我无法获得响应时获得响应? 问题是客户端还是服务端? 我查看了大量的在线资源,但无法实现它们

为了避免CORS,我尝试在自己的PC上托管该服务,但仍然出现了相同的错误

我已经在IIS中配置了自定义头


你有没有尝试过这个url:insteaf的url:u也可以尝试这个插件以获得合适的soap请求,