动态请求输入的 Web 服务请求问题
try
{
const string siteURL = "http://ops.epo.org/2.6.1/soap-services/document-retrieval";
const string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id='EP 1000000A1 I ' page-number='1' document-format='SINGLE_PAGE_PDF' system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";
var request = (HttpWebRequest)WebRequest.Create(siteURL);
request.Method = "POST";
request.Headers.Add("SOAPAction", "\"document-retrieval\"");
request.ContentType = " text/xml; charset=utf-8";
Stream stm = request.GetRequestStream();
byte[] binaryRequest = Encoding.UTF8.GetBytes(docRequest);
stm.Write(binaryRequest, 0, docRequest.Length);
stm.Flush();
stm.Close();
var memoryStream = new MemoryStream();
WebResponse resp = request.GetResponse();
var buffer = new byte[4096];
Stream responseStream = resp.GetResponseStream();
{
int count;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);
} while (count != 0);
}
resp.Close();
byte[] memoryBuffer = memoryStream.ToArray();
System.IO.File.WriteAllBytes(@"E:\sample12.pdf", memoryBuffer);
}
catch (Exception ex)
{
throw ex;
}
上面的代码是检索 pdf webresponse。只要请求保持不变,它就可以正常工作,
const string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id='EP 1000000A1 I ' page-number='1' document-format='SINGLE_PAGE_PDF' system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";
但是如何通过动态请求检索相同的内容。当上面的代码更改为接受动态输入时,例如,
[WebMethod]
public string DocumentRetrivalPDF(string docid, string pageno, string docFormat, string fileName)
{
try
{
........
.......
string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id=" + docid + " page-number=" + pageno + " document-format=" + docFormat + " system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";
......
........
return "responseTxt";
}
catch (Exception ex)
{
return ex.Message;
}
}
它返回“内部服务器错误:500”任何人都可以帮助我吗???
try
{
const string siteURL = "http://ops.epo.org/2.6.1/soap-services/document-retrieval";
const string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id='EP 1000000A1 I ' page-number='1' document-format='SINGLE_PAGE_PDF' system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";
var request = (HttpWebRequest)WebRequest.Create(siteURL);
request.Method = "POST";
request.Headers.Add("SOAPAction", "\"document-retrieval\"");
request.ContentType = " text/xml; charset=utf-8";
Stream stm = request.GetRequestStream();
byte[] binaryRequest = Encoding.UTF8.GetBytes(docRequest);
stm.Write(binaryRequest, 0, docRequest.Length);
stm.Flush();
stm.Close();
var memoryStream = new MemoryStream();
WebResponse resp = request.GetResponse();
var buffer = new byte[4096];
Stream responseStream = resp.GetResponseStream();
{
int count;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
memoryStream.Write(buffer, 0, count);
} while (count != 0);
}
resp.Close();
byte[] memoryBuffer = memoryStream.ToArray();
System.IO.File.WriteAllBytes(@"E:\sample12.pdf", memoryBuffer);
}
catch (Exception ex)
{
throw ex;
}
The code above is to retrieve the pdf webresponse.It works fine as long as the request remains canstant,
const string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id='EP 1000000A1 I ' page-number='1' document-format='SINGLE_PAGE_PDF' system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";
but how to retrieve the same with dynamic requests. When the above code is changed to accept dynamic inputs like,
[WebMethod]
public string DocumentRetrivalPDF(string docid, string pageno, string docFormat, string fileName)
{
try
{
........
.......
string docRequest = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><document-retrieval id=" + docid + " page-number=" + pageno + " document-format=" + docFormat + " system='ops.epo.org' xmlns='http://ops.epo.org' /></soap:Body></soap:Envelope>";
......
........
return "responseTxt";
}
catch (Exception ex)
{
return ex.Message;
}
}
It return an "INTERNAL SERVER ERROR:500" can anybody help me on this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内部服务器错误仅仅意味着服务器上出现问题。这通常意味着服务器抛出了未处理的异常。
在 Windows 事件日志中查找答案。特别是查看应用程序事件日志。
顺便说一句,你的代码很糟糕。
using
块中实例化。Internal Server Error simply means there's something wrong on the server. It usually means that the server has thrown an exception which was not handled.
Look in the Windows Event logs for an answer. In particular, look in the Application event log.
By the way, your code is pretty bad.
using
blocks.