Web Service 移除 xmlns

原作者:点部落·当麻许

链接:http://www.dotblogs.com.tw/junegoat/archive/2012/09/10/c-sharp-webservice-remove-xmlns.aspx

 

[C#] Web Service 移除 xmlns

最近因為一些業主要求,所以他需要我吐出去Web Service 的 XML 不能帶有  xmlns ..

 

也就是 原本是

 

2012-09-10_113819

 

但是他們家DEV 希望看的是

 

2012-09-10_113934

 

也真夠懶得…

 

不過付錢者大,看一下原本一開始的ASMX 檔案 是長這樣…

 

using System.Web.Services;
 
namespace TestNoneAttrService
{
    /// <summary>
    /// Summary description for ServiceSample2
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ServiceSample2 : System.Web.Services.WebService
    {
 
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

 

這時候我們要修改 將

 


[WebService(Namespace = http://tempuri.org/)]  換成      [WebService(Namespace = "", Description = "此 Web 服務不符合 WS-I Basic Profile v1.1")]

 

再將     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 移除 ,不然會出現

 

 

2012-09-10_113819

 

因為程式會去執行檢查的動作..所以必須要移除     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  這一行..

所以之後程式碼會變成..

 

 

using System.Web.Services;
 
namespace TestNoneAttrService
{
    [WebService(Namespace = "", Description = "此 Web 服務不符合 WS-I Basic Profile v1.1")]
   
    [System.ComponentModel.ToolboxItem(false)]
    
    public class ServiceSample : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

 

 

2012-09-10_114116

 

右邊為修改前, 左邊為修改後

 

 

執行結果:

 

2012-09-10_114455

 

其實會提出相對應的警告,但是執行為正常的..

 

2012-09-10_114540

 

reference : http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/be1c812b-503e-4d35-9f0c-9f12b9aaf406

 

給有碰到的人 :)

posted @ 2013-02-04 16:08  maksheiev  阅读(713)  评论(1编辑  收藏  举报