1. 先上调用代码

             public static string PostMoths(string url, string Json)
    {
    System.Net.HttpWebRequest request;
    Stream writer;
    System.Net.HttpWebResponse response; try
    {
    string strURL = url;
    System.GC.Collect();
    System.Net.ServicePointManager.Expect100Continue = false;
    request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
    System.Net.ServicePointManager.DefaultConnectionLimit = ;
    request.ServicePoint.ConnectionLimit = ;
    request.KeepAlive = false;
    request.Timeout = * * ;
    request.Method = "POST";
    request.ProtocolVersion = HttpVersion.Version11;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
    request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
    string paraUrlCoded = Json;
    byte[] payload;
    payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
    request.ContentLength = payload.Length;
    writer = request.GetRequestStream();
    writer.Write(payload, , payload.Length); response = (System.Net.HttpWebResponse)request.GetResponse();
    System.IO.Stream s;
    s = response.GetResponseStream();
    string strValue = "";
    StreamReader Reader = new StreamReader(s, Encoding.UTF8);
    strValue = Reader.ReadToEnd();
    if (request != null)
    {
    request.Abort();
    request = null;
    }
    if (response != null)
    {
    response.Close();
    response = null;
    }
    if (writer != null)
    {
    writer.Close();
    writer = null;
    }
    return strValue;
    }
    catch (Exception ex)
    {
    var obj = new
    {
    status = ,
    msg = ex.Message
    };
    request = null;
    response = null;
    writer = null;
    return ex.Message;
    }
    finally
    {
    request = null;
    response = null;
    writer = null;
    }
    }
  2. 配置文件信息 WebConfig
     <system.web>
    <!--解决本地调用成功,外网调用失败的问题-->
    <webServices>
    <protocols>
    <add name="HttpSoap"/>
    <add name="HttpPost"/>
    <add name="HttpGet"/>
    <add name="Documentation"/>
    </protocols>
    </webServices>
    <!--上传文件大小限制-->
    <httpRuntime executionTimeout="" maxRequestLength="" useFullyQualifiedRedirectUrl="false" requestValidationMode="2.0"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" validateRequest="false"/>
    </system.web>

    配置文件中红色标注是必填项。

  3. webservice接口代码
         [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
    [System.Web.Script.Services.ScriptService]
    public class MESService : System.Web.Services.WebService
    {
    [WebMethod(Description = "")]
    public void GetData(string strXML)
    {
    //你的结果处理
    #region 处理数据 #endregion
    Context.Response.Write(Common.JsonHelper.SerializeToJson(new { status = , msg = strXML }));
    Context.Response.End();
    }
    }
  4. 接口参数
     <?xml version="1.0" encoding="UTF-8"?>
    <LineEqui
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <LineCode>W1</LineCode>
    <EquiCode>qwe</EquiCode>
    <PlanStatus>Running</PlanStatus>
    <DataTime>2018-02-02 09:34:16</DataTime>
    <FactoryCode></FactoryCode>
    <ProductCode></ProductCode>
    <PlanCount></PlanCount>
    <Unit>PC</Unit>
    <Batch></Batch>
    <Area>山东</Area>
    <AreaCode>SD</AreaCode>
    <PlanCode></PlanCode>
    </LineEqui>
  5. 调用结果

    

HttpWebRequest,HttpWebResponse C# 代码调用webservice,参数为xml的更多相关文章

  1. c# 纯代码调用 webservice

    public static class RequestHelper { public class RequestResult { public RequestResult(bool requestRe ...

  2. C#调用WebService(服务引用-xml)

    情形:做接口调用三方WebService,WebService地址外网无法访问 方案: Step1:内网环境(可访问三方WebService地址,此处地址以http://127.0.0.1/WebSe ...

  3. Salesforce 使用Js 调用Webservice实例

    1,创建 Custom Button 在页面上 2, 创建CustomJs 代码调用Webservice <!--参数名区分大小写,对于跨层object直接在Object名后直接加参字段名即可- ...

  4. java接口调用——webservice就是一个RPC而已

    很多新手一听到接口就蒙逼,不知道接口是什么!其实接口就是RPC,通过远程访问别的程序提供的方法,然后获得该方法执行的接口,而不需要在本地执行该方法.就是本地方法调用的升级版而已,我明天会上一篇如何通过 ...

  5. Java调用WebService方法总结(5)--Axis2调用WebService

    Axis2是新一点Axis,基于新的体系结构进行了全新编写,有更强的灵活性并可扩展到新的体系结构.文中demo所使用到的软件版本:Java 1.8.0_191.Axis2 1.7.9. 1.准备 参考 ...

  6. 存储过程系列之存储过程sql数据库调用和程序代码调用

    1.存储过程,无参数的存储过程 创建无参数存储存储过程 Create Procedure DCEMREMR_TEMPLATEAs SELECT TOP 10 [FILENAME],[FILETITLE ...

  7. cxf 生成客户端代码调用服务

    cxf是另一种发布webservice的方式,与jdk提供的相比 jdk提供的是wsimport cxf 提供的是 wsdl2java- d 地址 根据http://www.cnblogs.com/f ...

  8. Java调用WebService方法总结(4)--Axis调用WebService

    Axis是比较常用的WebService框架,该项目在2006实现了最终版,后面就没有更新了.文中demo所使用到的软件版本:Java 1.8.0_191.Axis 1.4. 1.准备 参考Java调 ...

  9. Java调用WebService方法总结(3)--wsimport调用WebService

    wsimport是JDK自带的把WSDL转成Java的工具,可以很方便的生成调用WebService的代码.文中所使用到的软件版本:Java 1.8.0_191. 1.准备 参考Java调用WebSe ...

随机推荐

  1. IDEA2017版本打可运行jar包并运行

    一.打JAR包 JAR:From modules with dependencies  将依赖一起打包 一般依赖放在与xx.jar同级的libs文件夹中 敲黑板,下图第一个框是输出jar包的位置,第二 ...

  2. [Linux][Madplay播放器移植mini2440(ARM9)]

    Madplay移植到mini2440全过程详解 madplay交叉编译 交叉编译器:arm-linux-gcc 3.4.1PC环境:RedHat-6 注意:最好在root权限下执行以下移植,否则在ma ...

  3. fitnesse - 用例创建编辑、管理、执行和日志

    fitnesse - 用例创建编辑.管理.执行和日志 2017-10-09 目录 1 用例创建编辑  1.1 用例创建  1.2 用例编辑2 用例管理3 用例测试执行和日志  3.1 用例测试执行  ...

  4. 使用Jmeter自带的 Http 代理服务器录制脚本

    最近要测试某个模块的压力测试,所以使用Jmeter录制脚本 1.       打开JMeter工具 创建一个线程组(右键点击“测试计划”--->“添加”---->“线程组”) 创建一个ht ...

  5. shell脚本之for循环

    shell脚本之for循环 author :headsen  chen       2017-10-18    09:50:41 个人原创,转载请注明.否则依法追究法律责任 1,cat forloop ...

  6. mybatis学习日记-day01

    Mybatis说明: MyBatis 使用简单的 XML或注解用于配置和原始映射,将接口和 Java 的POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的 ...

  7. 部署在eclipse上的Tomcat上的publish和clean的区别

    publish:就是把自己的web应用发布到tomcat服务器上没这样才能通过浏览器查看浏览 clean: 就是先清除掉原先编译到tomcat上的程序(多个.class文件),之后再发布. 如:我建了 ...

  8. Jenkins集成Docker镜像实现自动发布

    1. 思路&流程 Jenkins集成Docker镜像实现自动发布与Jenkins发布mavne项目思路一样总体流程 为:Jenkins 拉去远端源码 -- gitl实现应用打包 -- jenk ...

  9. Tomcat 开启Gzip压缩

    原理简介         HTTP 压缩可以大大提高浏览网站的速度,它的原理是,在客户端请求服务器对应资源后,从服务器端将资源文件压缩,再输出到客户端,由客户端的浏览器负责解压缩并浏览.相对于普通的浏 ...

  10. 使用 js 设置组合快捷键,支持多个组合键定义,还支持 React

    ╭┈┈╮ ╭┈┈╮ ╭┈┈╮ ┆ ├┈┈..┈┈┈┈┈.┆ └┈╮┆ ├┈┈..┈┈┈┈┈..┈┈.┈┈..┈┈┈┈┈. ┆ ┆┆ □ ┆┆ ┈┤┆ < ┆ -__┘┆ ┆ ┆┆__ ┈┈┤ ╰ ...