日期:2014-05-18  浏览次数:21742 次

(急)Webservice的Content-Type问题
最近做了一个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。这个怎么改呢,我都没弄过,请高手帮忙一下。

------解决方案--------------------
http://topic.csdn.net/t/20030707/20/2000969.html
------解决方案--------------------
你的部署方法可能不对
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="u