客户端发现响应内容类型为“application/dime”,但应该是“text/xml”。到底是什么回事

sonkey 2006-04-11 11:51:21
我用程序调用一个带附件的wse2 webservice就出现:
客户端发现响应内容类型为“application/dime”,但应该是“text/xml”。请求失败,错误信息为: -- ))
请问怎么回事
...全文
524 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
添加WSE引用
添加Web引用
然后在解决方案管理器里
Web Reference文件夹下有两个代理文件
使用时要用 带WseAdv的那个
sonkey 2006-04-12
  • 打赏
  • 举报
回复
我都引用了,还是不行,晕,我基本上是按照wse2的帮助来做的。

然后导入WS引用 会添加2个引用文件
用的时候用Adv里面的

这两句话是什么意思啊?
adv是什么?
  • 打赏
  • 举报
回复
是不是Winform没添加WSE引用啊
项目上右键选WSE2.0Settings
钩上Enable WSE in this project
然后导入WS引用 会添加2个引用文件
用的时候用Adv里面的
sonkey 2006-04-12
  • 打赏
  • 举报
回复
我用winform程序就会出现
客户端发现响应内容类型为“application/dime”,但应该是“text/xml”。请求失败

用webform就不会出现。
  • 打赏
  • 举报
回复
客户端代码示例:


1 private void button2_Click(object sender, System.EventArgs e)
2 {
3 int offset = 0;
4 int buffersize = 3* 1024*1024;
5 bool bComplete = false;
6 FileStream fs = null;
7 string sFileName = textBox1.Text;
8 Adb.AdvWse adv = new TestWebSrv.Adb.AdvWse();
9 byte[] buffer = new byte[buffersize];
10 int size = 0;
11 int result = 0;
12 System.DateTime time = DateTime.Now;
13
14 while( !bComplete )
15 {
16 Application.DoEvents();
17 try
18 {
19 result = adv.GetPartitionAttachment(sFileName,offset,buffersize);
20 if (result == 0)
21 {
22 bComplete = true;
23 break;
24 }
25 if (adv.ResponseSoapContext.Attachments.Count != 0)
26 {
27 fs = new System.IO.FileStream(sFileName,FileMode.OpenOrCreate,FileAccess.Write);
28 fs.Seek(0,SeekOrigin.End);
29 size = adv.ResponseSoapContext.Attachments[0].Stream.Read(buffer,0,buffersize);
30 fs.Write(buffer,0,result);
31 offset += result;
32 textBox2.Text = offset.ToString()+"Bytes Received\r\n" + textBox2.Text;
33 Application.DoEvents();
34 }
35 else
36 {
37 bComplete = true;
38 break;
39 }
40 }
41 finally
42 {
43 fs.Close();
44 }
45
46 System.TimeSpan time1 = DateTime.Now - time;
47 this.Text = time1.ToString();
48 }
49
50
51 }
52
  • 打赏
  • 举报
回复
去年写的代码
绝对能用的
  • 打赏
  • 举报
回复
你的客户端添加WSE引用没?
sonkey 2006-04-12
  • 打赏
  • 举报
回复
楼上的方法也是同样的错误:

源错误:


行 71: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetPartitionAttachment", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 72: public int GetPartitionAttachment(string sFileName, int offset, int size) {
行 73: object[] results = this.Invoke("GetPartitionAttachment", new object[] {
行 74: sFileName,
行 75: offset,


源文件: e:\dkdsoft\wes_test\wse_web\web references\wse2\reference.cs 行: 73

堆栈跟踪:


[InvalidOperationException: 客户端发现响应内容类型为“application/dime”,但应该是“text/xml”。
请求失败,错误信息为:
--
))?uuid:e11edee1-6f1b-4a22-b68d-83538e9eb022http://schemas.xmlsoap.org/soap/envelope/<?xml version="1.0" encoding="utf-8"?><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" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><soap:Header><wsa:Action>http://tempuri.org/GetPartitionAttachmentResponse</wsa:Action><wsa:MessageID>uuid:b946c99c-d087-48ae-b29c-cb96f77bc7be</wsa:MessageID><wsa:RelatesTo>uuid:3f8ac7f9-2cc9-4b88-adf4-c1c48182ba24</wsa:RelatesTo><wsa:To>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:To><wsse:Security><wsu:Timestamp wsu:Id="Timestamp-afd801be-05e5-4088-be0f-b496a2f6ae88"><wsu:Created>2006-04-12T01:35:50Z</wsu:Created><wsu:Expires>2006-04-12T01:40:50Z</wsu:Expires></wsu:Timestamp></wsse:Security></soap:Header><soap:Body><GetPartitionAttachmentResponse xmlns="http://tempuri.org/"><GetPartitionAttachmentResult>1000</GetPartitionAttachmentResult></GetPartitionAttachmentResponse></soap:Body></soap:Envelope>
?Fileimage/jpg????JFIF??C



%# , #&')*)-0-(0%()(??C



(((((((((((((((((((((((((((((((((((((((((((((((((((????"??
???}!1AQa"q2???#B??R??$3br?
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz???????????????????????????????????????????????????????????????????????????
???w!1AQaq"2?B???? #3R?br?
$4?%?&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz????????????????????????????????????????????????????????????????????????????m5&?M?[? 8??p??j
I?C??????-???????\??s????Gmc?EP*?t??br,?????y?????(A?sX????"?7?S?2~????^????M??L???0????????????????P*???-k?J???]?C??|#y&?E?N?????uz~?ea????<?????V?4?????w?#????????L????Sl#??N4{Sr???v??????????s?oDt?J;??
?"???.v??"S$?}B.X?U???:(?^mj???h?a?V?F9?!.??v?kf?-??%??h?????"????A?C???#?? lr?6?u??M?W??e?X{???*+LxRX???
--.]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
WSE_web.WSE2.WSE.GetPartitionAttachment(String sFileName, Int32 offset, Int32 size) in e:\dkdsoft\wes_test\wse_web\web references\wse2\reference.cs:73
WSE_web.WebForm1.Button1_Click(Object sender, EventArgs e) in e:\dkdsoft\wes_test\wse_web\webform1.aspx.cs:51
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain() +1277

  • 打赏
  • 举报
回复
你试着返回一个值看
WS端应该是没问题的

这是我写的一个下载附件的
能用
/**//// <summary>
2 /// 分块下载附件
3 /// </summary>
4 /// <param name="sFileName">文件名</param>
5 /// <param name="offset">文件起始偏移量</param>
6 /// <param name="size">一次读取大小</param>
7 /// <returns>返回附件文件大小</returns>
8 [WebMethod]
9 public int GetPartitionAttachment( string sFileName,int offset, int size)
10 {
11 string[] names = sFileName.Split("\\".ToCharArray());
12 string filename=Server.MapPath(names[names.Length - 1]);
13
14 byte[] buffer = new byte[size];
15 FileStream fs = new FileStream(filename, FileMode.Open,FileAccess.Read,FileShare.Read);
16 fs.Seek(offset,SeekOrigin.Begin);
17 int numBytes;
18 if((numBytes = fs.Read(buffer,0,size)) > 0)
19 {
20 try
21 {
22 MemoryStream ms = new MemoryStream(buffer,0,size);
23 ms.Seek(0,SeekOrigin.Begin);
24
25 ResponseSoapContext.Current.Attachments.Add(new dime.DimeAttachment("File","image/jpeg",dime.TypeFormat.MediaType,ms));
26 return numBytes;
27 }
28 finally
29 {
30 fs.Close();
31 }
32 }
33 else
34 {
35 return 0;
36 }
37
38 }
sonkey 2006-04-12
  • 打赏
  • 举报
回复
to net_lover:
请问在那里改呢?
ws里面的方法代码如下:
public void GetAttachment(string imageName)
{
SoapContext myContext = ResponseSoapContext.Current;
string filePath = Server.MapPath("images\\" + imageName + ".txt");

DimeAttachment dimeImage = new DimeAttachment(
"text/txt", TypeFormat.MediaType, filePath);
dimeImage.Id = "tmpPic1.jpg";

//将新的DimeAttachment对象添加到SoapContext对象中,
myContext.Attachments.Add(dimeImage);
}
  • 打赏
  • 举报
回复
你的调用方使用了WSE么?
sonkey 2006-04-12
  • 打赏
  • 举报
回复
问题已经解决。
sonkey 2006-04-12
  • 打赏
  • 举报
回复
我项目里面没有
添加WSE引用 这一项啊!
只有
添加Web引用 这一项。
孟子E章 2006-04-11
  • 打赏
  • 举报
回复
类型不一致

application/dime改为text/xml

12,166

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧