ajax调用webservice注意事项

1.weservice客户端需要注意(跨域请求)


   
   
     
       
       
       
     

   

 

2.ajax请求

var soapdata='{"subject":"测试电话李明远","cicc_contactid": null,"cicc_direction":"10","ownerid":"A6B254F4-6A49-E611-80BE-005056BD7FD2","cicc_contacts_text":"白展堂","cicc_if_im": null,"scheduleend":"2017-10-10 09:00:00","schedulestart":"2017-10-10 08:00:00","cicc_requestdepartment": null,"cicc_talktime": null,"description": null,"cicc_phonenumber": null,"cicc_company": null,"cicc_source": null}';
var soap=' '+soapdata+'';
 $.ajax({
                type: "POST",
                url: "http://loacalhost/PortalService/PortalService.asmx?InsertPhonecall ",
                data:soap,
                contentType: "application/soap+xml",
                charset:"utf-8",
                cache: false,
                dataType:"xml",
                async: false,
                success: function (data) { debugger; alert(data.firstChild.textContent); },
                error: function (data) { console.log(data);}
            });

分析一波soap格式,注意在soap1.2版本中<方法名 xmlns="http://tempuri.org/"><参数名>参数

另外可以参考网页中涉及的传输方法

SOAP 1.1

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /PortalService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Hi"



  
    
      string
    
  
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length



  
    
      string
    
  

SOAP 1.2

以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /PortalService.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length



  
    
      string
    
  
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length



  
    
      string
    
  

HTTP POST

以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。

POST /PortalService.asmx/Hi HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

hi=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length


string


你可能感兴趣的:(C#)