最近做了一个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。这个怎么改呢,我都没弄过,请高手帮忙一下。

解决方案 »

  1.   

    http://topic.csdn.net/t/20030707/20/2000969.html
      

  2.   

    你到底是json,xml soap还是使用post提交。
      

  3.   

    我就是写一个普通的Webservice,C#下写好编译就能用的那种也不知道是用什么提交的,请问这个怎么看啊?
      

  4.   

    web.config里面也要配置的。参见
    http://dotnet.aspx.cc/file/call-aspnet-web-service-using-javascript.aspx
      

  5.   


    http://localhost:18316/WebSite1/WebService.asmx?op=GetDataTable
    页面就能看到HTTP POST需要的Content-Type:了
      

  6.   

    完整的代码都在链接里面了,POST提交的,你看了没?
    如果对方说错误,那么你们的调用接口没有商量好
      

  7.   

    是这样的,对方的小型机上的代码是不能改的,一定要我这里改,我这里的测试是这样的
    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
    ....
      

  8.   

    你的部署方法可能不对
    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>注意红色部分的不同