我们正试图与网络服务器(可能是JBoss)交谈,但它对.NET生成的请求感到窒息。如果我们手动创建SOAP,它可以工作,但我们不想这样做 - 我们必须为WSDL中的每个方法执行此操作。唯一真正的区别是XML声明的存在。麻烦的是,我无法弄清楚如何摆脱它。我无法修改请求流。有人可以提供一些建议吗?
public partial class CustomClient : GeneratedClient
{
protected override WebRequest GetWebRequest(Uri uri)
{
var webRequest = base.GetWebRequest(uri);
webRequest.Method = "POST";
var requestStream = webRequest.GetRequestStream();
// Next line cannot execute -- Stream is not readable.
var soapEnvelope = new StreamReader(requestStream).ReadToEnd();
GOOD REQUEST(手动创建):
POST https://remotewebserver.org/productname/service HTTP/1.1
Authorization: Basic BIGLONGBASE64
SOAPAction: ""
Content-Type: text/xml; charset=utf-8
Host: remotewebserver.org
Content-Length: 378
Expect: 100-continue
Connection: Keep-Alive
<soapenv:Envelope>
<soapenv:Body>
<con:QueryLimitRequest>
<username>email@address.com</username>
<password>PA$$W0RD</password>
<organization>Our Company Name</organization>
<con:requestType>QueryLimit</con:requestType>
<con:processingType>TESTING</con:processingType>
</con:QueryLimitRequest>
</soapenv:Body>
</soapenv:Envelope>
BAD REQUEST(自动生成):
POST https://remotewebserver.org/productname/service HTTP/1.1
Authorization: Basic BIGLONGBASE64
SOAPAction: ""
Content-Type: text/xml; charset=utf-8
Host: remotewebserver.org
Content-Length: 532
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?> <!-- XML Declaration I want to remove -->
<soap:Envelope>
<soap:Body>
<QueryLimitRequest xmlns="http://namespace.remotewebserver.org">
<username>email@address.com</username>
<password>PA$$W0RD</password>
<organization>Our Company Name</organization>
<requestType>QueryLimit</requestType>
<processingType>TESTING</processingType>
</QueryLimitRequest>
</soap:Body>
</soap:Envelope>