跟國外公司的測試過程已經基本完成了,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一致.