windows窗体应用程序调用webservice,响应消息的内容类型不匹配

congtouzailai110 2018-07-20 07:43:13
使用ASP.Net开发了一个WebService(WS),然后又开发了一个Windows窗体应用程序(Exe),Exe通过服务引用调用了WS。

WS、Exe都在开发机上时:一切正常,通过浏览器、或Exe都能能正常访问WS,成功返回字符串“消息发送成功”或“消息发送失败”。

WS部属到服务器时:浏览器仍然能正常访问。但无论Exe部属在开发机还是服务器,都不能正常访问WS,提示错误如下:

未处理System.ServiceModel.ProtocolException
HResult=-2146233087
Message=响应消息的内容类型 text/html; charset=utf-8 与绑定(application/soap+xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节为:“

查询了网上很多办法,折腾了一个下午,未能解决,求大神指点。

环境:
开发机:win7 64、vs2013、.Net4.0
服务器:ws2003 sp2、.Net4.0、IIS6.0

WS的代码:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Net
Imports System.IO

' 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class SendMsgToEMessage
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function SendMsg(Gonghao As String, MsgTitle As String, MsgContent As String, LinkText As String, LinkUrl As String) As String
Dim url As String = "http://xxx.xxx.xxx.xxx/social/PushRemindWebService.jsp?method=pushExternal&title=" & MsgTitle & _
"&requesttitle=" & LinkText & _
"&requestdetails=" & MsgContent & _
"&requesturl=" & LinkUrl & _
"&receiverIds=" & Gonghao & _
"&key=3d0786ea-13df-44cb-9d23-e0413323ebd5"
'接收保存数据
Dim request As WebRequest = WebRequest.Create(url)
Dim response As WebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"))
Dim returnStr As String = reader.ReadToEnd()
reader.Close()
reader.Dispose()
response.Close()
If returnStr <> "True" Then
Return "消息发送成功"
Else
Return "消息发送失败"
End If
End Function
End Class


Exe的代码:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim msg As New WS.SendMsgToEMessageSoapClient
TextBox1.Text = msg.SendMsg("123", "测试", "'测试", "", "")
Catch ex As Exception
TextBox1.Text = ex.Message
End Try
End Sub
...全文
122 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
congtouzailai110 2018-07-23
  • 打赏
  • 举报
回复
没人关心一下吗,顶一下

12,162

社区成员

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

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