java 跟.net webservice 互連問題(3)

來源:互聯網
上載者:User

跟國外公司的測試過程已經基本完成了,web service的互連問題也已經解決.

需要注意的是:

1,命名空間一定要一致

2,必須確保兩種web service的soap 包格式相同.

下面用代碼解釋一下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using NLog;

namespace TestService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://www.test.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement, Use = SoapBindingUse.Literal)]
    //[SoapRpcService(RoutingStyle = SoapServiceRoutingStyle.RequestElement, Use = SoapBindingUse.Literal)]
    public class testService : System.Web.Services.WebService
    {

                   [WebMethod]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
        [return: System.Xml.Serialization.XmlElementAttribute("outstr", Namespace = "http://www.test.com/")]
        public string test([System.Xml.Serialization.XmlElementAttribute("input", Namespace = "http://www.test.com/")] string inputstr)
             {
            try
            {
                Logger log = LogManager.GetCurrentClassLogger();

                
                #region 記錄日誌
                if (inputstr!=null)
                {
                    log.Info("inputstr=" +inputstr);
                    }
                }
                #endregion

                return inputstr;
            }
            catch (Exception ex)
            {
               
                throw ex;
            }

        }
    }
   
}

上邊的代碼是用nlog這個開源組件簡單的記錄了一個日誌,我們可以定義webservice的命名空間和輸入參數和返回參數的命名空間,來達到跟java一致.

黃色的部分代碼是關鍵,這樣做可以協助你自訂soap 包格式,保持跟java一致.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.