最近做了一个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。这个怎么改呢,我都没弄过,请高手帮忙一下。
Content-Type: application/x-www-form-urlencoded。这个怎么改呢,我都没弄过,请高手帮忙一下。
http://dotnet.aspx.cc/file/call-aspnet-web-service-using-javascript.aspx
http://localhost:18316/WebSite1/WebService.asmx?op=GetDataTable
页面就能看到HTTP POST需要的Content-Type:了
如果对方说错误,那么你们的调用接口没有商量好
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
....
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: lengthid=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>注意红色部分的不同