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

 

給有碰到的人 :)

转载于:https://www.cnblogs.com/maksheiev/archive/2013/02/04/2891952.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值