(急)Webservice的Content-Type问题

hzpdh 2012-05-04 10:57:44
最近做了一个C#写的Webservice,供小型机连。对方一直说报错,直接在IE里打开测试界面的Content-Type项是Host: 28.90.0.61;Content-Type: application/json; charset=utf-8;Content-Length: length...他说要用Host: 28.90.0.61
Content-Type: application/x-www-form-urlencoded。这个怎么改呢,我都没弄过,请高手帮忙一下。
...全文
1753 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzpdh 2012-05-31
  • 打赏
  • 举报
回复
问题已解决 给分的两个稍微靠谱
hzpdh 2012-05-04
  • 打赏
  • 举报
回复
post提交的
hzpdh 2012-05-04
  • 打赏
  • 举报
回复
是的 我看到了,问题是怎么改掉呢
孟子E章 2012-05-04
  • 打赏
  • 举报
回复

http://localhost:18316/WebSite1/WebService.asmx?op=GetDataTable
页面就能看到HTTP POST需要的Content-Type:了
孟子E章 2012-05-04
  • 打赏
  • 举报
回复
web.config里面也要配置的。参见
http://dotnet.aspx.cc/file/call-aspnet-web-service-using-javascript.aspx
hzpdh 2012-05-04
  • 打赏
  • 举报
回复
我就是写一个普通的Webservice,C#下写好编译就能用的那种也不知道是用什么提交的,请问这个怎么看啊?
threenewbee 2012-05-04
  • 打赏
  • 举报
回复
你到底是json,xml soap还是使用post提交。
hzpdh 2012-05-04
  • 打赏
  • 举报
回复
这个我早看过了,没写方法
孟子E章 2012-05-04
  • 打赏
  • 举报
回复
你的部署方法可能不对
Content-Type: text/xml; charset=utf-8

这种是SOAP 1.1格式的,建议你使用VS2010开发,部署到asp.net4.0下应该就可以,
可以实现 HTTP POST 方法


http://dotnet.aspx.cc/HelloWebService.asmx?op=HelloWorld
这种就不行,没有HTTP POST方法
参照
http://dotnet.aspx.cc/file/call-aspnet-web-service-using-javascript.aspx

在asp.net4下可以有

SOAP 1.1
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebSite1/WebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetDataTable"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetDataTable xmlns="http://tempuri.org/">
<id>int</id>
</GetDataTable>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetDataTableResponse xmlns="http://tempuri.org/">
<GetDataTableResult>string</GetDataTableResult>
</GetDataTableResponse>
</soap:Body>
</soap:Envelope>

SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebSite1/WebService.asmx HTTP/1.1
Host: localhost
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetDataTable xmlns="http://tempuri.org/">
<id>int</id>
</GetDataTable>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetDataTableResponse xmlns="http://tempuri.org/">
<GetDataTableResult>string</GetDataTableResult>
</GetDataTableResponse>
</soap12:Body>
</soap12:Envelope>

HTTP POST
以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。

POST /WebSite1/WebService.asmx/GetDataTable HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

id=string
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>

注意红色部分的不同
hzpdh 2012-05-04
  • 打赏
  • 举报
回复
是这样的,对方的小型机上的代码是不能改的,一定要我这里改,我这里的测试是这样的
POST /WebServiceWX/Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetResult"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetResult xmlns="http://tempuri.org/">
<InfoXml>string</InfoXml>
</GetResult>
</soap:Body>
</soap:Envelope>
他的错误日志是这样的
发送HTTP请求如下:
POST /Service.asmx/GetResult HTTP/1.1
Host: 28.90.61.60
Content-Type: application/x-www-form-urlencoded
Content-Length: 105
....
孟子E章 2012-05-04
  • 打赏
  • 举报
回复
完整的代码都在链接里面了,POST提交的,你看了没?
如果对方说错误,那么你们的调用接口没有商量好

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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