我正在开发soap web服务。我在tomcat中成功运行它。但是当我将它部署到weblogic时,发生了错误。我从头文件发送用户名和密码到Web服务,但发生如下错误:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:vw="http://vw.com/">
<soapenv:Header>
<username>operator</username>
<pass>xxxxxx</pass>
</soapenv:Header>
<soapenv:Body>
<vw:createParams>
<!--Optional:-->
<arg0>app1</arg0>
<!--Optional:-->
<arg1>All</arg1>
</vw:createParams>
</soapenv:Body>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns0:Fault xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.w3.org/2003/05/soap-envelope">
<faultcode>ns0:Server</faultcode>
<faultstring>javax.xml.soap.SOAPException: Header child element 'username' must be namespace qualified!</faultstring>
</ns0:Fault>
</S:Body>
</S:Envelope>
任何想法?
答案 0 :(得分:1)
public string Get(int CSI_ID)
{
const string username = "********";
const string password = "********";
string url = @"https://globalfunctionsshare.nam.citi.net/";
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
NetworkCredential credentials = new NetworkCredential(username, password, "eur");
var path = @"sites/otdrrm/_layouts/15/download.aspx?SourceUrl=%2Fsites%2Fotdrrm%2FDocuments%2Ftools%2FLegal%20Hold%20Application%20Tracker/Legal%20Hold%20Application%20Tracker%2020210702.xlsx";
DownloadFile(url, credentials, path);
DataTable dt = ImportExceltoDatatable(@"C:\Users\mk20317\Legal_Hold_Application_Tracker.xlsx", CSI_ID);
string Status = dt.Rows[0]["Preservation Status"].ToString();
return Status;
}
private static void DownloadFile(string webUrl, ICredentials credentials, string fileRelativeUrl)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
using (var client = new System.Net.WebClient())
{
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
client.Headers.Add("User-Agent: Other");
//client.Credentials = credentials;
client.Credentials = CredentialCache.DefaultCredentials;
client.DownloadFile(new Uri(webUrl + fileRelativeUrl), @"C:\Users\mk20317\Legal_Hold_Application_Tracker.xlsx");
//var data = client.DownloadString(webUrl + fileRelativeUrl);
//JObject table = JObject.Parse(data);
}
}
public DataTable ImportExceltoDatatable(string Filepath, int CSI_ID)
{
// string sqlquery= "Select * From [SheetName$] Where YourCondition";
string sqlquery = "Select [Preservation Status] From [App List$] Where [CSI ID]=" + CSI_ID;
DataSet ds = new DataSet();
string constring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Filepath + ";Extended Properties=\"Excel 12.0;HDR=YES;\"";
OleDbConnection con = new OleDbConnection(constring + "");
OleDbDataAdapter da = new OleDbDataAdapter(sqlquery, con);
da.Fill(ds);
DataTable dt = ds.Tables[0];
return dt;
}
答案 1 :(得分:0)
SOAP要求标头元素是名称空间限定的。如果您正在对此进行编码,请使用QName作为用户名并传递元素
答案 2 :(得分:0)
虽然SOAP标准确实要求头元素是名称空间限定的,但似乎只有weblogic实现才会检查它。 Tomcat使用JDK实现,该实现接受没有命名空间的头文件。
要在weblogic中使用相同的设置,您必须在war文件中包含saaj-impl,并告诉weblogic您要在weblogic.xml文件中使用该实现。
weblogic.xml中的相关部分:
<wls:prefer-application-packages>
<wls:package-name>javax.xml.soap.*</wls:package-name>
</wls:prefer-application-packages>
如果你正在使用maven,添加它以在你的包中加入saaj-impl。
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.4.0</version>
</dependency>