WebService 因URL意外地以”/…”结束,请求格式无法识别--我的解决方案

问题产生场景:自定义一个Web Service,放到SharePoint站点下。(说明:我开发的不是SharePoint的Web Service,只是一个普通的,因为要在sharepoint站点中使用,所以放在sharepoint站点下面。)

产生的错误:在服务器上面访问时没有问题,但是在客户端的IE访问时有如下的错误:异常信息:     异常类型: InvalidOperationException     异常消息: 因 URL 意外地以“/GetEncryptString”结束,请求格式无法识别。

Web Services方法代码如下:

Code Snippet
  1. [WebMethod]
  2.         public string GetEncryptString(string userLoginName)
  3.         {
  4.             //Code
  5.         }

js调用代码如下:(使用的是JQuery调用Web Service的方式)

Code Snippet
  1. $.ajax({
  2.                             async: false,
  3.                             type: "POST",   //访问WebService使用Post方式请求
  4.                            url: "/WebService.asmx/GetEncryptString", //调用WebService的地址和方法名称组合---WsURL/方法名
  5.                            dataType: 'xml',
  6.                             contentType: "text/xml; charset=\"utf-8\"",
  7.                             success: function(data) {
  8.                                    urlParamter=data.text;
  9.                              } ,    
  10.                             error:function(response)
  11.                             {
  12.                               alert(response.responseTEXT);
  13.                             }
  14.                     });  

 

解决:

网上的解决方案大部分都是:

要在webservice的 <system.web> 节点下加入 
<webServices> 
          <protocols> 
              <add   name= "HttpPost "   /> 
              <add   name= "HttpGet "   /> 
          </protocols> 
</webServices>

当然,我要修改的是sharepoint站点本身的web.config。会不会有什么影响?我不知道,所以尝试其他的解决方案。

参考JQuery调用sharepoint Services的方式

Code Snippet
  1. var soapEnv =
  2.            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> ..."
  3.       $.ajax({
  4.             url: "/school/_vti_bin/lists.asmx",
  5.             type: "POST",
  6.             dataType: "xml",
  7.             data: soapEnv,
  8.             complete: processResult,
  9.             contentType: "text/xml; charset=\"utf-8\""
  10.       });

我做了改动,下面是修改之后的内容:

Code Snippet
  1. var soapEnv="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  2.                            xmlns:xsd='http://www.w3.org/2001/XMLSchema'
  3.                            xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
  4.                           <soap:Body>
  5.                             <GetEncryptString xmlns='http://tempuri.org/'>
  6.                             <userLoginName>"+userloginName+"</userLoginName>
  7.                             </GetEncryptString>
  8.                           </soap:Body>
  9.                         </soap:Envelope>";
  10.          $.ajax({
  11.                             async: false,
  12.                             type: "POST",   //访问WebService使用Post方式请求
  13.                             url: "/WebService.asmx", //调用WebService的地址和方法名称组合---WsURL/方法名
  14.                             dataType: 'xml',
  15.                             data: soapEnv,
  16.                             contentType: "text/xml; charset=\\cf1 "utf-8\"",
  17.                             success: function(data) {
  18.                                    urlParamter=data.text;
  19.                              } ,    
  20.                             error:function(response)
  21.                             {
  22.                               alert(response.responseTEXT);
  23.                             }
  24.                     });  
参考的是:http://blog.csdn.net/abedon/archive/2002/10/29/3921.aspx这个自定义SOAP头消息,SOAP的格式参考我的web Service。

image

总结:我对于Sharepoint的Web Service机制还没有做深入的了解,可能是限制不安全的自定义的Web Services访问吧。

posted @ 2010-01-07 17:18  范文轩  阅读(5885)  评论(0编辑  收藏  举报