我正在尝试使用SOAP与Java Web服务进行通信,并且我在解析响应时遇到问题(response = null)。我在本网站上看到了很多关于SOAP响应= null的问题/答案,其中大多数似乎都与响应名称空间不匹配,与代码中的配置相匹配。我面临的问题是我从服务器获得的响应根本不包含名称空间。
这是请求:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Body><AuthenticatePassword xmlns="urn:SOAPService"><userName>administrator</userName> <password>administrator</password></AuthenticatePassword></SOAP-ENV:Body></SOAP-ENV:Envelope>
以下是回复:
<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body><AuthenticatePasswordResponse><Status>OK</Status></AuthenticatePasswordResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
请注意,响应中没有命名空间条目(即xmlns =“urn:SOAPService”或甚至xmlns =“”)。我无法控制服务器,我没有要解析的WSDL,所以我手动配置代理类:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name = "AdminService", Namespace = "urn:SOAPService")]
public partial class AdminService : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public AdminService()
{
}
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
public AuthenticatePasswordResponse AuthenticatePassword(AuthenticatePassword AuthenticatePassword)
{
object[] results = this.Invoke("AuthenticatePassword", new object[] {
AuthenticatePassword});
return ((AuthenticatePasswordResponse)(results[0]));
}
}
我已尝试设置SoapDocumentMethodAttribute ResponseNamespace =“”,但会抛出异常。我也尝试过ResponseNamespace = null,但这没有帮助。
有任何想法或建议吗?
更新:
我尝试使用WCF,处理响应时收到SerializationException:
OperationFormatter遇到无效的Message正文。期望找到名为'AuthenticatePasswordResponse'的节点类型'Element'和名称空间'urn:SOAPService'。找到名为'AuthenticatePasswordResponse'的节点类型'Element'和名称空间''
以下是我如何定义AuthenticatePasswordReponse(我也试过[DataContract(NameSpace =“”)]:
[DataContract]
public class AuthenticatePasswordResponse
{
private string statusField;
private string sessionField;
[DataMember]
public string Status
{
get { return this.statusField; }
set { this.statusField = value; }
}
[DataMember]
public string session
{
get { return this.sessionField; }
set { this.sessionField = value; }
}
}